Wait for Animation Event Node

nathanj

Member
Hey @Justin

Can you see why this script wouldn't be receiving an animation event? I'm trying to set up a wait for animation node - it's based off the wait for animation state node.

Thanks in advance,
Nathan

Code:
namespace BehaviorDesigner.Runtime.Tasks.Unity.UnityAnimator
{
    [TaskCategory("Unity/Animator")]
    [TaskDescription("Waits for an Event from the Animator")]
    public class WaitForAnimationEvent : Action
    {

        [Tooltip("The GameObject that the task operates on. If null the task GameObject is used.")]
        public SharedGameObject targetGameObject;
      
        private bool canContinue = false;

        public override void OnStart()
        {
            EventHandler.RegisterEvent(targetGameObject, "OnContinueAnimatorComplete", SendAnimEvent);
        }

        private void SendAnimEvent()
        {
            canContinue = true;
            Debug.Log("Event Recieved");
        }

        public override TaskStatus OnUpdate()
        {
            Debug.Log("Waiting For Event");
            if (canContinue) {
                Debug.Log("Event Executed");
                return TaskStatus.Success;
            }
            return TaskStatus.Running;
        }

        public override void OnReset()
        {
            targetGameObject = null;
            canContinue = false;
            EventHandler.UnregisterEvent(targetGameObject, "OnContinueAnimatorComplete", SendAnimEvent);
        }
    }
}
 

Justin

Administrator
Staff member
Is the task active? It looks like you are registering for the event within OnStart. You may want to use OnAwake instead.

You'll also want to make sure the target GameObject is pointing to the character that is sending the event.
 

nathanj

Member
Thanks Justin,


The event is still not being connected. Even if I manually assign the NPC through the inspector window. I'm heading out for the weekend but will pick up next week. I'll let you know if I I get it sorted.

Thanks again!
Nathan
 
Last edited:

Justin

Administrator
Staff member
Do you have a OnContinueAnimatorComplete event being sent? On UCC you can debug the events by enabling Log Animator Events on the Animator Monitor.
 

nathanj

Member
Thanks for pointing me in the right direction Justin, I didn't know the debugger existed on the Animator Window, though it is now glaringly obvious 🤦‍♂️

I've posted the functioning script in the Integrations thread incase it is useful for others. I'm definitly gonna be using it alot.

WaitForAnimationEvent
 
Top