On-end Decorator being called when Destroying BT

How can I prever a on-end decorator from being called when the BT is being destroyed/Disabled:

Code:
public class TeleportOnEnd : OnEndDecorator
    {
        public SharedGameObject target;

        AstarAgent astarAgent;

        public override void OnAwake()
        {
            astarAgent = GetComponent<AstarAgent>();
        }

        public override TaskStatus Decorate(TaskStatus status)
        {
            if (target.Value == null)
                return status;

            if (astarAgent.isPathfindingDisabled)
            {
                transform.position = target.Value.transform.position;
            }
            else
            {
                astarAgent.Teleport(target.Value.transform.position);
                astarAgent.Stop();
            }

            return status;
        }
    }

1681466130490.png
 
When the behavior tree is destroyed the behavior tree completes all of the tasks before it is completely stopped. You aren't able to change this without modifying the runtime source.

With that said, your code looks like it belongs more in an Action task rather than a Decorator. The Decorator is designed to only change the task status based on the child but you are changing game state. If you restructure your tasks you shouldn't need to change the runtime.
 
When the behavior tree is destroyed the behavior tree completes all of the tasks before it is completely stopped. You aren't able to change this without modifying the runtime source.

With that said, your code looks like it belongs more in an Action task rather than a Decorator. The Decorator is designed to only change the task status based on the child but you are changing game state. If you restructure your tasks you shouldn't need to change the runtime.

Thanks, okay. I actually find decorators super useful for these types of cases. Is there not some code I can add that check if BT is being destroyed or disabled, and if it is, I just skip my logic?
 
Top