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?
The issue would be loading time, and memory.
Don’t do that. Instantiate items as you need them.
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.
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!! ![]()
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?
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.
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.
You can load that data asynchronously. If it is in an asset bundle, it is straight forward to load it then.
http://docs.unity3d.com/ScriptReference/AssetBundle.LoadAsync.html
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.
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.
Wouldn’t that just be a matter of creating zones and/or checking distance to the player?
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.
Thanks Tony, this really helps a lot! ![]()