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

Accessing BlendTrees properties.

Discussion in 'Immediate Mode GUI (IMGUI)' started by mambo_2, Jun 7, 2015.

  1. mambo_2

    mambo_2

    Joined:
    Aug 19, 2013
    Posts:
    19
    Hello,

    I am working on creating a tool that copies one whole controller with it's substate machines, transitions, parameters and layers, copying is working as supposed to right now but one problem I am facing is blendtrees, the main problem is I can replicate them, I can add children and copy the motion but I can not reproduce animation speeds, mirroring or thresholds, I tried changing them from their serialized properties directly that did not work and my guess is they are linked to an editor field and unless I access that I can not change them since unity probably applies the modified properties depending on the changes to those toggle fields, my last option was using reflection but I do not know where to start with it, any help would be great.

    Below you can find a snippet of the code am working with.



    Code (CSharp):
    1. if (stateMachine.states[i].state.motion.GetType() == typeof(UnityEditor.Animations.BlendTree))
    2.                 {
    3.                     UnityEditor.Animations.BlendTree oldBlendTree = stateMachine.states[i].state.motion as UnityEditor.Animations.BlendTree;
    4.                     UnityEditor.Animations.BlendTree newBlendTree = new UnityEditor.Animations.BlendTree();
    5.  
    6.                     newBlendTree.blendParameter = oldBlendTree.blendParameter;
    7.                     newBlendTree.blendType = oldBlendTree.blendType;
    8.  
    9.                     for (int j = 0; j < oldBlendTree.children.Length; j++)
    10.                     {
    11.                         newBlendTree.AddChild(oldBlendTree.children[j].motion, oldBlendTree.children[j].threshold);
    12.                         newBlendTree.children[j].timeScale = oldBlendTree.children[j].timeScale;
    13.                         newBlendTree.children[j].position = oldBlendTree.children[j].position;
    14.                         newBlendTree.children[j].threshold = oldBlendTree.children[j].threshold;
    15.                         newBlendTree.children[j].directBlendParameter = oldBlendTree.children[j].directBlendParameter;
    16.                     }
    17.  
    18.  
    19.                     newState.motion = newBlendTree;
    20.                 }
    21.             }
     
  2. mambo_2

    mambo_2

    Joined:
    Aug 19, 2013
    Posts:
    19