Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

What is the performance overhead for disabled submeshes on characters?

Discussion in 'Scripting' started by Sendatsu_Yoshimitsu, Dec 25, 2014.

  1. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    I'm considering implementing customizable clothing in the simplest way possible, by adding each possible article that requires a mesh (jackets, shoes, pants) to the master model, and enabling/disabling them at runtime based on what the character is wearing. This is easy to implement, but I'm worried about the performance cost- is the overhead of maintaining, say, 80-100 diasbled clothing submeshes, each well under 10k polys, negligible? Or is this likely to become a major performance issue in the long run?
     
  2. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,716
    The issue would be loading time, and memory.

    Don't do that. Instantiate items as you need them.
     
    BenZed likes this.
  3. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    As mentioned in the S-Inventory thread, it's often worthwhile to rig the flexible meshes (jackets, shoes, pants) to the model and enable/disable them. This allows you to make sure they're rigged properly to follow the character's skeleton without having to do any complex runtime setup. There's no performance penalty, and you probably need the meshes in memory anyway to show in the player's inventory window, or shopkeeper interfaces, or on other characters that share the same model.

    You don't necessarily need a lot of submeshes. You can make dozens of robe variations (red velvet, rough burlap, paisley, Charlie Brown's zig-zag pattern, etc.) using different textures and shaders on a single robe mesh.

    To save memory, you can instantiate and parent rigid meshes (helmets, shields, swords). But if you need them in memory anyway for other characters or interfaces, you might prefer to have them all pre-rigged.
     
  4. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    That is awesome, I was incorrectly under the impression that I was going to have to do a whole heap of labor to get this working, thank you!! :)
     
  5. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,541
    Correct me if I'm wrong, because I'm not 100% sure, but since the clothes are being switched in (I'm guessing) a menu shouldn't it not matter if it is expensive? Like isn't that the reason Fallout and Elder Scrolls games chug when switching equipment?
     
  6. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    That's a good point. And it really depends on the game. If I recall correctly, World of Warcraft characters have all equipment pre-rigged. You typically see a lot of different characters onscreen with different gear, so you'd have all those meshes loaded anyway. But if it's more of a single-player dress-up game with lots of very different, detailed meshes, it might be better to load them as needed.
     
  7. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,541
    Now, and this is really getting ahead of myself, but I also think that those games load things as you get near them so that there is no skip when a new enemy is in range. That's streaming data, and that is like magic to me.
     
  8. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Not_Sure likes this.
  9. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    At the risk of getting off topic, there's also Resources.LoadAsync if you're not using asset bundles. Although it's been obsoleted in Unity 5, there's a workaround. But @Not_Sure I hear you. It's not enough to be able to load async; you also need to know when to load and unload assets.
     
  10. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    At the risk of asking the obvious question, if you're loading data asynchronously does it remain pre-rigged? I'm going for something closer to a Saint's Row approach to wardrobe, even with only having unique meshes for the jacket, pants, shoes, and gloves I'll probably end up with close to 50-75 unique meshes that need to play nice with the character rigging, which is why I'm having trouble figuring out what the most efficient way to store and switch them out is. If simply rigging everything into a single model in blender and manually toggling the desired submesh is fast, it's alluringly simple, but I hate the idea of holding anything in memory that I don't need constantly.
     
  11. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,541
    Wouldn't that just be a matter of creating zones and/or checking distance to the player?
     
  12. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    I haven't yet had a need to do it myself, but you should be able to set Mesh.boneWeights to copy the bone weights from your base onto a runtime-loaded mesh. Here's an article with code that someone wrote about it.

    That would be how I'd approach it -- add a trigger collider to the NPC, and when the player enters check a table of assets and make sure everything the NPC will need is loaded. Never done it for meshes, though.
     
  13. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    Thanks Tony, this really helps a lot! :)