I’m thinking of the pros and cons of modeling AI Behavior in BP vs C++ or a mix of both and some questions arises so far:
In the example project Shooter Game the logic for handling calculations is put into the AIController (i.e. FindClosestEnemyWithLOS) and hooked up via a BTService_Blueprint in the BehaviorTree. Is it practical to write a separate C++ BTServices i.e BTService_FindClosestEnemyWithLOS and use it directly in th BT? I’m thinking of a generic way to reuse such services like it is done with the BTTs (i.e. BTTask_HasLosTo).
Why is ShootAnEnemy a BTService and no BTTask?
Thanks for your opinions!
The best practice is to have heavy-lifting code done in C++ and just trigger it from BT or blueprints. If you want to trigger a thing and wait for the result, use a task. If you want to keep on triggering the thing while BT is in particular execution branch, then use services.
Regarding service in ShooterGame’s Bot BT let me copy-paste the answer I gave on UDN:
This is actually a pretty smart way of setting up aggressively shooting AI.
Services are basically a way to run a piece of code on a regular basis in sync with BT state, meaning this given service will be ticked only as long as it’s part of active execution branch.
In this specific case it’s on the root node, which means it’s being ticked always (every 0.5 second) and what it does it’s checking if AI can see it’s target and if AI’s weapon can shoot. If so then fire away, if not, another try in 0.5 second.
You can just as well make shooting a task, but that would be more or a “deliberate” action, like a sequence “move there and shoot”. You can also use a SimpleParallel composite node to implement shooting while moving. AFAIR ShooterGame’s AI has been build when SimpleParallel haven’t existed yet.
Thanks for your answer mieszko!