Shared Exp on Behavior Tree Starter tutorial (converting to c++)

I first did the tutorial:
then I wanted to learn how to do some of it in c++ and some of it in BluePrints.

As part of learning process and because I knew later on, I wanted some c++ control in this area.

I just wanted to share my experiences, as I wasn’t having much luck searching and here is hoping that someone in the future can find this useful.

After a bit of badluck on search, I finally stumbled upon tomlooman’s survival tutorial, that covers some of what I wanted.
e.g. EpicSurvivalGameSeries/SZombieAIController.h at master · tomlooman/EpicSurvivalGameSeries · GitHub
Specifically focus on the ZombieAIController

Later on I realized, he did a few things you don’t even need too!

The first thing I wanted to do, was to convert my AIController class to c++
So instead of Follower_AI_CON as stated in the Behavior Tree tutorial. I made a FollowerAIConCpp base class (that inherits from AAIController)

Adding a few needed things.

class BEHAVIORTREESTARTER1_API AMyFollowerAICon : public AAIController
	void BeginPlay();
	UPROPERTY(EditDefaultsOnly, Category = "AI")
	class UBehaviorTree* BehaviorTree;

	UPROPERTY(EditDefaultsOnly, Category = "AI")
	FName HomeLocation;

In the beginning, I had this more sloppy approach

and later realized it could be condensed down to simply

void AMyFollowerAICon::BeginPlay()
	UseBlackboard(BehaviorTree->BlackboardAsset, Blackboard);
	Blackboard->SetValueAsVector(HomeLocation, GetPawn()->GetActorLocation());

If you weren’t inheriting from AAIController, you may need to make your own blackboard and behaviorcomp members, more similar to the Zombie one.

Since I still wanted to have both the blueprint AND c++ version run off the same Service,Task,Decorator. Yet in the original BehaviorTree Tutorial, they had saved a Reference to AI_CON_ref

I found a work around (although I am not sure if this is a good/bad approach)

The below is original way, The top is my new way
New AgroCheck:

I replace all the references with OwnerActor>Target-Instigator>GetController

Alternatively, I could have likely changed the Follower_AI_Con to a simple AIIController or something, it all depends upon the behavior that you want! But this was enough for me, for now.

New CloseEnough:
New RapidMoveTo

Then since I had my core AIBehavior in C++, the 1 thing it was missing. was that member variable for the Behavior Tree itself.

So I created a blueprint (FollowerAIConCppBP) with my new c++ class as its parent. And then I could set the Class Defaults Behavior Tree to the FollowerBT
I know I can set the HomeLocation = “HomeLocation”; but I do not know how to get the BehaviorTree asset via C++ (any suggestions?)

Then I could make my animated character to have this new blueprint as the AI controller

For those who may stumble upon this later. It really is a good idea to search the github repo, by the blueprint nodes name (if you are following a tutorial) and see what they did or do. Perhaps you can call the same functions or mimic some of the behavior. I have found this to be still be a better resource than random internet searching still.