Creating a custom service using C++
Now that we have finished creating the behavior tree for our AI, it is about time we go about setting the blackboard keys that a large amount of our logic is based on. We are going to do this with a service. As stated previously, a service is something that will take place at a certain frequency or tick. Services act as a way to update AI information and states during runtime from the behavior tree. We have created enough BT assets using blueprint, so it is time we create one in C++! The purpose of this service is to check an area around the AI for an ABMCharacter, if one is found, set it as the target for the AI to follow.
Start by creating a new C++ class via the wizard, this time the class will inherit from BTService. Ensure you do not inherit from BTService_BlueprintBase as that abstraction is to only be used by blueprints. Call this new class BMAgroCheck. Once the engine has generated the new code files, navigate to BMAgroCheck.h.