admin管理员组文章数量:1424264
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?
本文标签:
版权声明:本文标题:unity game engine - How do you get a prefab w Skinned Mesh Renderer to attach to an avatar on instantiation? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744681661a2619445.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论