OnEnd() Issue

BustedTuna

New member
In short, my OnEnd() method seems to be running when the task starts, and I am not sure what I am doing wrong.

All my code is handwritten, so I imagine I have messed something up. Basically, I have a conditional (WithinSight) that checks if the player is in sight and, if it is, runs the action ChasePlayer to chase the player. When the object loses sight of the player, it sends the last known location to a SharedVector3 called clueLocation and returns failure. To the right is a conditional (ClueCheck) that checks if clueLocation is not equal to Vector3.zero and (if it isn't) then runs the Investigate action that tells the object to move towards the clueLocation.value.

The issue is that the OnEnd() method of the Investigate task sets clueLocation.value to Vector3.zero and OnEnd() seems to be happening at the start of the action. The research I did implied that OnEnd() should run at the success/failure/interruption of a task but I may have misread something.

I have these two questions:
1) When does the OnEnd() method run?
2) Is there a way to ensure that clueLocation is reset to Vector3.zero whether the Investigate action succeeds/fails/is interrupted?


I have included below the tree and the scripts for ChasePlayer and Investigate. If any additional information is necessary, please let me know. Also, if I have posted this in the wrong place, or made an error in posting, I sincerely apologize, as this is my first post.

Update: I unchecked "Instant" on the ClueCheck conditional and now it works as intended, but I am still not sure what was causing the issue in the first place. Does OnEnd() hold over the "ending" of other tasks in a sequence? (Not sure how to phrase this)

Behavior Tree
1bdtree.png
Chase Player Action
4chaseplayer.png
Investigate Action
2investigate.png
 
Last edited:
Update: I unchecked "Instant" on the ClueCheck conditional and now it works as intended, but I am still not sure what was causing the issue in the first place. Does OnEnd() hold over the "ending" of other tasks in a sequence? (Not sure how to phrase this)
Glad you got it. No, OnEnd should be called after a Success/Failure has been returned from the task. If you enable logging on the behavior tree component you may be able to track down the flow for when OnEnd is being called.
 
Top