I have a blueprint that switches between 2 behavior trees based on world state using RunBehaviorTree.
In one behavior tree, I have a task node that calls MoveToActor. It then binds to the OnMoveCompletedEvent. When the move completed event happens, it unregisters for the OnMoveCompletedEvent and then calls FinishExecute.
I also unregister for OnMoveCompleted in EventReceiveAbort.
When I switch trees, I get an assert failure in UBehaviorTreeComponent::OnTaskFinished. The OnMoveCompletedEvent is being called on the node in the “old” tree. It then calls FinishExecute. When the BehaviorTreeComponent tries to find the instance of the node, it is using the “current” tree instead of the “old” one. The node is no longer in the InstanceStack of the BehaviorTreeComponent.
How do I properly unregister for any events in a blueprint task? Or how do I abort a currently running task in a behavior tree?