Issues with SharedMeshRenderers and changing them (aka, armor and helms)

Hey all, so my current project is pushing me to learn how to do armor and helm changes on my character model. I’ve never done this sort of thing before but felt like I was up to the challenge!

At the moment I have a single character model which serves as the base. I then added in a armor mesh, and a helmet mesh. Both are separate objects within the same 3DS Max file. I then rigged all 3 objects, (Skin, Armor, Helm) to a biped with excellent results. I took the same base and did this for 3 more sets of armor and helmets with the intention of switching them out via script at runtime. This is where the challenges first started coming in.

I made a color picker setup and allowed the player to change their characters skin color which works fine. But as I switched the skins I found some very odd results. Before continuing I would like to note that before I made all these armor and helm models I tested my theory using a simple model of him naked and another with armor and it worked perfect. But with my new armors and helms only 3 work as intended, the other 1 does not. It does the same thing as the armors, where it skews all crazy!

So at this point I thought I’d do some reviewing of my objects individually. So when dragging and dropping my models into the editor and reviewing each helmet I noticed that 3 (all the working ones) had the same root bone on that mesh where as the one that didn’t had a different root bone. If I changed the rootbone to the same as the others then applied those others to that one it seemed to work perfectly fine. It was at this point that I realized my issue may have been with bones. Though I’m not sure why only that one was different as all helmets were rigged exactly the same. So not sure why it imported differently.

So if you want to see a video on this issue you can see it on my forum post here.

Bwahahahahahahahahaaha! I finally got it! I found out how to properly switch meshes despite having different rig setups without having to stitch together stuff or long coding!!! It was such a frustrating learning experience but so satisfying once I had it!

So the issue is when switching meshes the meshes must have similar bone setup otherwise they don’t work. It gets all skewed, implodes, explodes, etc. And you can’t just grab the correct bones from the prefab of the armor. Doing this would make the mesh properly skin, but not at the right location or to the biped we are using either because we are grabbing those bones specifically from that other skeleton which wont work for this one.

This made me think about how I go about getting the right bones from the proper skeleton. Then it clicked! I need a list of the bones in the armor required, then check through the bones of my current rig and fetch them into a list. I can then apply this list to my current mesh after it’s been changed to the one I want.

So now my meshes and armors are fully changeable despite their bones with only like 20 lines of code. Or about 40 if you include the reference array for each armor, helm, and skin color.