Search Unity

Dealing with model assets question

Discussion in 'Getting Started' started by Bill_Martini, Jan 10, 2017.

  1. Bill_Martini

    Bill_Martini

    Joined:
    Apr 19, 2016
    Posts:
    445
    I'm tinkering with a 3rd person quest game idea and I want to have nine different characters the user can choose from. Only one of the nine will be used in game. All nine will be prefabs, each has their own materials and textures. I need to know the best / proper way to handle these assets. Are there different approaches and are there pro's and con's or gotcha's to be aware of?
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    There are different approaches, but two immediately leap to mind:
    1. Throw all nine prefabs into a "Resources" folder, which means they will be available to your game (by path/name) via the Resources module.
    2. Make yourself a CharacterManager class with a public GameObject[] array, and just drag your nine prefabs into that. Then this class can present the character choices, keep track of which is selected, and make it available to the rest of your game.
    As usual, the best choice is whichever one seems easiest/clearest to you. Don't over-think it.
     
  3. Bill_Martini

    Bill_Martini

    Joined:
    Apr 19, 2016
    Posts:
    445
    Thanks Joe,

    That was a pretty poorly worded question, made in haste, sorry. You seemed to grasp the gist anyway.

    The question should have been more like; What is the most efficient way to handle models for overall game size and memory usage.

    I'm trying to minimize game size and memory footprint. I have nine humanoid models, similar to 'Ethan' but probably not as optimized. Each model has their own materials and textures.

    I see 3 ways of handling this. Load model from Resources folder (as you mentioned), Instantiate from an array of prefabs, or place in scene and make all but one inactive. Having all in scene would slam memory (i'm guessing), but does having them in an array require the same memory usage? Is there a difference in file size keeping the models internal or placing in a Resources folder? What is the best way for fast scene loading? How best to minimize the impact of eight unused models, as only one is used in game?
     
  4. smacbride

    smacbride

    Joined:
    Jan 10, 2015
    Posts:
    50
    You can load them in when a user selects one, they won't use any memory until you load one. They will only take up space on the disk. I'm doing that exact thing in my game. When I load a character it appears instantly. I'm running Windows 10 on an Intel i7 box.
     
  5. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I'm going to argue (again) that you're worrying far too much, far too early.

    Again, the chief problem most games face isn't that they use too much memory. Nor is it that characters take too long to appear. It is, by far, that the game never gets finished at all.

    So it really is wrong to be trying to optimize for memory or speed at this stage. You should be optimizing for what is quick to write and easy to maintain.

    Don't worry that doing so will develop bad habits... prematurely optimizing, or writing needlessly complex code, is by far the worse habit.

    But if it makes you feel better, embrace encapsulation. When faced with a choice like this, your chief objective should be simply to hide the choice from the rest of the code. So in this case, you would make a CharacterManager script whose job it is to get the character — somehow — in some way that is only its business, and none of the rest of the code knows or cares where it comes from. Maybe it orders the character Amazon Prime Same-Day Shipping; who knows?

    The only thing you need to do carefully is define this interface that hides how it works. And then, you go inside it, and from all the ways you might implement it, choose the quickest and easiest. Why? Because of all the reasons above, and because it literally doesn't matter — since if the day ever comes that you find an actual need to do it differently, you only have to go inside this one module, and change that. None of the rest of the code is affected, because you hid the details from it in the first place.
     
    Bill_Martini likes this.
  6. Bill_Martini

    Bill_Martini

    Joined:
    Apr 19, 2016
    Posts:
    445
    Thanks Joe,

    I understand your 'Any way you can get it done' view as this will 'get it done'. And I'm not worried about learning bad habits, I've done that long ago. I'm trying to unlearn bad habits while learning Unity. I'm either over thinking or under thinking. Analysis paralysis is a problem for me that I usually overcome by information overload. It's amazing I get anything done.

    Every project I'm doing is focused on a particular Unity feature. A while back it was to learn multiplayer. BTW that project is still single player and trying to use Unet was a complete failure. This project is to learn Mechenim. Lets hope this turns out better than Unet...

    Clearly the easiest for me would be to drop all nine prefabs in the scene and activate the one to be used. That seems goofy to me. Instantiating is not new to me, and I guess getting the prefab by name, isolates from the rest. I'm more leaning towards loading from a resource folder, as I haven't done that before and it makes the most sense to me.

    My second goal is to work on my environmental design skills, terrain, structures, props and build a decent 3rd person controller to work with mechenim animations. I guess I can worry about how I'm going to bring in my character later. Right now all I have is an untextured plane and one of my models in T-pose. I guess I have a couple of other things I could be doing, while mulling this over.
     
    JoeStrout likes this.