Here's a useful node script for waiting for an animation event.
You can change the string value if you have parallel functions running and are waiting for unique events.
Disclaimer: there might be an issue with manually connecting your game object to the node. I think that at the moment this will only work if the field is null. I'll have to research this further tomorrow.
You can change the string value if you have parallel functions running and are waiting for unique events.
Disclaimer: there might be an issue with manually connecting your game object to the node. I think that at the moment this will only work if the field is null. I'll have to research this further tomorrow.
Code:
using Opsive.UltimateCharacterController.Events;
using UnityEngine;
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;
public string eventName = "OnContinue";
private GameObject targetObject;
private bool canContinue = false;
public override void OnAwake()
{
targetObject = GetDefaultGameObject(targetGameObject.Value);
EventHandler.RegisterEvent(targetObject, eventName, SendAnimEvent);
}
private void SendAnimEvent()
{
canContinue = true;
}
public override TaskStatus OnUpdate()
{
if (canContinue) {
return TaskStatus.Success;
}
return TaskStatus.Running;
}
public override void OnReset()
{
targetGameObject = null;
canContinue = false;
EventHandler.UnregisterEvent(targetObject, eventName, SendAnimEvent);
}
}
}
Attachments
Last edited: