Can't run behavior tree

Hello there!

I have a problem with assigning behavior tree to the newly spawned AActor.
My actor have empty AIController assigned to it.
But I need to do it out of AIController, in my spawner instead.

This task is quite easy in blueprint and looks like that:

My current code, what need to do the same here:

void AMobSpawner::SpawnMob(FMobType mobType)
{
	ACharacter* character = GetWorld()->SpawnActor<ACharacter>(mobType.character, GetActorLocation(), FRotator(0.f, 0.f, 0.f), FActorSpawnParameters());
	
	OnSpawnProgress(character, currentWave, currentSubWave, spawnedInTotal, spawnedInTotal, spawnedInWave, needToSpawnInWave);

	AController* ai = character->AIControllerClass.GetDefaultObject();

	// TODO: Ok, what next?
}

Can’t find this “Run Behavior Tree” function…

This function is inside AAIController class. In your case you had just a generic “AController” which surely doesn’t have any direct BT relations.

So as soon as you can cast your controller to you can call that from BP/C++

virtual bool RunBehaviorTree(UBehaviorTree* BTAsset);

Isn’t it better to run the behaviour tree inside the AIController class? and just make sure the AI is auto possessed when spawned or placed in the world.

I would run the behaviour tree in the AIController on beginplay event.