Making a spawnAI blueprint function but cannot see arguments in BP

I am attempting to make a function in C++ that a blueprint will call to spawn an AI.
I am using the AIBPLibrary function SpawnAIFromClass as my basis. However I am running into problems spawning the behaviour tree.

SpawnAIFromClass has the argument “class UBehaviorTree* BehaviorTree” and, obviously, this shows up as modifiable argument in blueprints.
however when I use this exact same argument in my custom function it doesn’t show up as a modifiable input in my blueprint.

How can I make it so I can input this in blueprint to my C++ function. What is SpawnAIFromClass doing that my c++ blueprint function isn’t?

It’s hard to tell without seeing any of your code :slight_smile:

Ahh sorry

void AMapChunkBase::spawnEnemies(class UClass* BehaviourTree)
{
	int i = FMath::Min(enemies.Num() - 1, spawnPoints.Num() - 1);

	UE_LOG(LogTemp, Log, TEXT("spawnSize Size %i"), i);
	while (i >= 0)
	{
		 //= (AActor*)GWorld->SpawnActor(enemies[i], new FVector(spawnPoints[i]->GetComponentLocation()));
		APawn* NewPawn = GWorld->SpawnActor<APawn>(enemies[i], spawnPoints[i]->GetComponentLocation(), spawnPoints[i]->GetComponentRotation());
		if (NewPawn != NULL)
		{
			if (NewPawn->Controller == NULL)
			{
				NewPawn->SpawnDefaultController();
			}

			AAIController* AIController = Cast<AAIController>(NewPawn->Controller);

			if (AIController != NULL)
			{
					AIController->RunBehaviorTree((UBehaviorTree*)BehaviourTree );
			}
		}
		enemiesRemaining++;
		i--;
	}
}

As you can see I literally copy pasted the portion of the Spawn from ai class code that I needed. My header is

`UFUNCTION(BlueprintCallable, Category = "Encounter")	
void spawnEnemies(class UClass* BehaviourTree);`

The context of this is I’m creating chunks of a map. And the chunks spawn the enemies when you walk over certain parts of them. The chunks are blueprints that inherit from this class.

You got your parameters wrong :slight_smile: Make your spawnEnemies take UBehaviorTree* BehaviorTree not a UClass. Behavior Trees created in the editor are assets, not classes :slight_smile:

Carry on, make some awesome AI! :smiley:

–mieszko

Sorry that was code I had edited trying to get this to work. UBehaviorTree* was what I started with and it doesn’t work either.

Ok but your code got it working and I think I figured it out.
Changing this base class function wasn’t updating the blueprint until I restarted UE4. When you posted your reply I restarted UE4 to check and got a drop-down for UClass. changing to UBehaviorTree in the code and recompiling didn’t change the blueprint function (even opening and closing the blueprint or recompiling it) however restarting UE4 again made the blueprint function update. I imagine in the first place the empty function I had originally was being kept in BP until I restarted and the Uclass one I compiled an hour ago was now used. This might be a bug.

Also thank you very much for your reply on a Sunday night. Thats some dedication and service I really appreciate!

You welcome. I just want to help whenever I can :smiley: