Sending Events to AI

I am writing a RTS kind of game where the player is able to command individual units, e.g. send them to a specific location. The player stores a command object, which contains a unique ID for each command type (such as moving to location or attacking a target) plus metadata which is command type specific (such as the location to move to or the actor to attack).

The command is stored in each unit and a behavior tree is responsible for executing them. My current issue lies in changing commands on the fly. Obviously, it is very important to change a command before the current command was executed. E.g. when a unit is moving to a location a player should be abled to command the unit to move to a different location without having to wait until the current movement is done.

My current setup to achieve this is the following: There is a task for each command type. A decorator makes sure that only the task for the current command ID will be executed. A service checks every so often weather the command has changed. If it has, the observer will abort.

This setup is not particularly good in my opinion. I dislike checking for a condition every so often (especially, because checking too rarely makes the units react with quite a delay). I would much rather use an approach where the unit’s pawn (which stores the current command) could tell the behavior tree that an update of the command has occurred. Optimally, this would completely remove the necessity of a service. Is there a way to do this? Notifying the behavior tree of some event from the outside?