I am working on a modular equipment system. The player will be able to swap out many pieces of gear and see it change on their model. I ultimately want to load the gear pieces through the addressables system. The problem I have is that the modular prefab pieces lose reference to the players rig (as you would expect since it’s in the scene) and stop rendering properly as a result.
I have tried creating a reference to all the bones for the prefab’s SkinMeshRenderer (via C#) but it doesn’t work properly. Here’s what I see. The left is the instantiated prefab as described above. The right is before I delete the newly created prefab from the scene, and thus it hasn’t lost the bones:
Here’s the code that produced this:
void AssignArmorToArmature()
{
// Instantiate the armor prefab
GameObject armorInstance = Instantiate(armorPrefab, Vector3.zero, Quaternion.identity, playerArmature.parent.parent);
armorInstance.transform.localPosition = Vector3.zero;
armorInstance.transform.localRotation = Quaternion.identity;
// Get the SkinnedMeshRenderer from the armor instance
SkinnedMeshRenderer armorRenderer = armorInstance.GetComponentInChildren<SkinnedMeshRenderer>();
armorRenderer.bones = playerArmature.GetComponentsInChildren<Transform>();
armorRenderer.rootBone = playerArmature;
}
I know that the model is weight painted correctly and the bones are named the same, so that doesn’t appear to be the issue. What else can I try?