Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Calling an Animation in Child Object

Discussion in 'Animation' started by the_terrible, Jan 9, 2019.

  1. the_terrible


    Nov 4, 2015
    Hi all,

    I've been calling different Spine animations I've created using the following code:
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using Spine.Unity;
    4. using Spine;
    5. public class Movement : MonoBehaviour
    6. {
    7.      TrackEntry activeTrackEntry;
    8.      SkeletonAnimation skeletonAnimation;
    10.      public string WalkToChaseEndEventName = "WalkToChaseEnd";
    12.      void Start()
    13.      {
    14.           skeletonAnimation = GetComponentInChildren<SkeletonAnimation>();
    15.           skeletonAnimation.state.Event += HandleEvent;
    16.      }
    18.      void HandleEvent(Spine.TrackEntry entry, Spine.Event e)
    19.      {
    20.           if (e.Data.Name == WalkToChaseEndEventName)
    21.           {
    22.                activeTrackEntry = skeletonAnimation.AnimationState.SetAnimation(0, "Chase", true);
    23.           }
    24.      }
    25. }
    The animator script imported from Spine is set to a child of the object this code is attached to which is why I'm using GetComponentInChildren. The problem I'm having is that I also have another object, ContextObject, set as a child of this object. ContextObject contains its own imported animations from Spine that I want to call as well. How do I call an animation to be played for the child ContextObject, not its parent?