I don't understand why this tree never enters the Send Event task even when Can Pass returns Success.
Here's an image of the log showing it reaches the return TaskStatus.Success.
I have removed all irrelevant code and managed to track it down to the CanDoPass method. It works fine when this method is hardcoded to return true but when I have any kind of condition that takes more than one frame it fails, even this simple counter I have right now and I really can't figure out why.
Here's an image of the log showing it reaches the return TaskStatus.Success.
I have removed all irrelevant code and managed to track it down to the CanDoPass method. It works fine when this method is hardcoded to return true but when I have any kind of condition that takes more than one frame it fails, even this simple counter I have right now and I really can't figure out why.
Code:
public class CanPass : Conditional
{
public SharedFloat CheckInterval;
private bool firstRun = true;
private float lastTime;
public override void OnReset()
{
CheckInterval = 1f;
}
public override void OnStart()
{
base.OnStart();
if (firstRun)
{
lastTime = Time.time;
firstRun = false;
}
}
public override TaskStatus OnUpdate()
{
if (Time.time - lastTime < CheckInterval.Value)
{
return TaskStatus.Failure;
}
lastTime = Time.time;
Debug.Log("CheckInterval time passed");
if (!CanDoPass())
{
return TaskStatus.Failure;
}
Debug.Log("CanDoPass returned true");
return TaskStatus.Success;
}
private int counter;
private bool CanDoPass()
{
return ++counter > 1;
}
}