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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[Unity 4.6] How to change skined mesh render after optimize game objects

Discussion in 'Scripting' started by sylar-huang, Aug 25, 2015.

  1. sylar-huang

    sylar-huang

    Joined:
    Dec 13, 2013
    Posts:
    4
    I found skined mesh render's bones empty after "Optimize game objects" enabled in the model rig, so I can't rebuild bones and replace with different skeleton share the same bones hierarchy like before . These codes are work well without this thing enabled

    Code (csharp):
    1.  
    2. SkinnedMeshRenderer s = go.GetComponentInChildren<SkinnedMeshRenderer>();
    3.  
    4. nbones.Clear();
    5. bones = _src.GetComponentsInChildren<Transform>();
    6.  
    7. foreach (Transform bone in s.bones) {
    8. foreach (Transform old in bones) {
    9. if (old.name != bone.name) {
    10. continue;
    11. }
    12. nbones.Add(old);
    13. break;
    14. }
    15. }
    16.  
    17. _renderer.bones = nbones.ToArray();
    18. _renderer.sharedMesh = s.sharedMesh;
    19. _renderer.materials = s.materials;
    20.  
     
  2. sylar-huang

    sylar-huang

    Joined:
    Dec 13, 2013
    Posts:
    4
    somebody help:eek::D:p:confused: