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 'General Discussion' started by sylar-huang, Aug 22, 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

    SkinnedMeshRenderer s = go.GetComponentInChildren<SkinnedMeshRenderer>();

    nbones.Clear();
    bones = _src.GetComponentsInChildren<Transform>();

    foreach (Transform bone in s.bones) {
    foreach (Transform old in bones) {
    if (old.name != bone.name) {
    continue;
    }
    nbones.Add(old);
    break;
    }
    }

    _renderer.bones = nbones.ToArray();
    _renderer.sharedMesh = s.sharedMesh;
    _renderer.materials = s.materials;
     
    Last edited: Aug 22, 2015
  2. sylar-huang

    sylar-huang

    Joined:
    Dec 13, 2013
    Posts:
    4
    somebody help o_O;)
     
  3. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,033
    Do not optimize them, because that's one effect of optimization(and probably the only one).
     
  4. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,141
    You'd have a better chance at answers if you post in the scripting section. Additionally you will want to use code tags.