Can't run behavior tree using c++

Hi guys!

I have a problem using behavior tree with c++.

At this point my behavior tree has nothing but just simple custom task which only have PrintString(AddOnScreenDebugMessage) function.

I think my problem is spawning character and it’s default AIController.

Below is part of my PlayerController class spawning a Character and it’s default AIController.

void AMyPlayerController::SpawnSquadMembers()
{
    FTransform tmpTransform;
    // Setting Translation, Rotation, Scale3D

    FActorSpawnParameters spawnInfo;
    APlayerCharacter* SquadMember = GetWorld()->SpawnActor<APlayerCharacter>(CharacterClass, tmpTransform, spawnInfo);

    if(SquadMember)
    {
        SquadMember->SpawnDefaultController();
        ACompanionController *aiController = Cast<ACompanionController>(SquadMember->GetController());
        if(aiController)
        {
            aiController->StartFollowing(num);
        }
    }
}

It actually Spawn the character and it’s AIController, then run the Controller’s StartFollowing Function.

Below is StartFollowing Function

void ACompanionController::StartFollowing_Implementation(int32 _squadNum)
{
 	if (GetPawn() && BehaviorTree)
 	{
 		APlayerCharacter* character = Cast<APlayerCharacter>(GetPawn());
 		if (character)
 		{
 			if (BehaviorTree->BlackboardAsset)
 			{
 				bool initialize = BlackBoardComp->InitializeBlackboard(*(BehaviorTree->BlackboardAsset));
 				if (initialize)
 				{
 					GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, FString(TEXT("Initializing Blackboard Success")));
 					UE_LOG(LogTemp, Warning, TEXT("Initializing Blackboard Success"));
 				}
 				else
 				{
 					GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, FString(TEXT("Initializing Blackboard Failed")));
 					UE_LOG(LogTemp, Warning, TEXT("Initializing Blackboard Failed"));
 				}
 				
 			}
 		}
 		SquadNum = _squadNum;
 		//BehaviourTreeComp->StartTree(*BehaviorTree);
 		RunBehaviorTree(BehaviorTree);
 		
 	}
}

All the AddOnScreenDebugMessage and UE_Log print its Success message so the function is called, But the BehaviorTree doesn’t run.

Above is Blueprint script that I have used to test my BehaviorTree but in Another Testing AIController class i created using BP.

And this one is the Testing AIController that starts BehaviorTree. This time the Behavior tree runs.

In PIE, I can find my custom AIController in world outliner, but when I opened up Behavior tree there’s no DebugObject, no back and forth flashing. Is there anyone can help me??

I figured it out myself.

The problem is AIController itself. I created my AIController class extending c++ AIController, then extend that to a BP class.

So I just created BP one(not extending my c++ class) then use it as a default ai controller, then it works.

Don’t know exactly what part of my c++ AIController was problem though.