- Home /
How to delete a state from the animator?
I've successfully made code that will add in a blendtree with the animations at set intervals that dynamically change dependent on how many motions are added. Where my code falls down is that it generates a new blend tree everytime it is called, which is everytime I press play.
Is there a way to alter this so that it deletes itself or changes itself instead of generating a new one?
public class AnimationSwitcher : MonoBehaviour
{
public List<Motion> animations;
public AnimatorController animator;
private BlendTree blendTree;
void Start()
{
animator.CreateBlendTreeInController("Active", out blendTree);
addMotions();
}
public void addMotions()
{
int numberAnimations = animations.Count;
for (int i = 0; i < animations.Count; i++)
{
Debug.Log(i);
blendTree.AddChild(animations[i], ((1 * i / numberAnimations)));
}
}
}
Answer by swanne · Sep 02, 2020 at 01:54 PM
Would wrapping your code in the Start function in an IF statement work? Only create the blend tree if one doesnt exist?
Your answer
Follow this Question
Related Questions
Animation doesn't play when set to non-looping 2D 0 Answers
Animation blend tree value glitching after reaching zero 2 Answers
Animations not working when I put them on Blend tree 0 Answers
cannot access two animation parameters in blend tree animations in Humanoid ? 0 Answers
Change animation of 4 Way Movement Sprites moving diagonally to last used non-diagonal direction? 0 Answers