Spawn Blueprint from C++ Error

Hi guys,
I have a little problem that i am not understanding.
I am spawning a blueprint actor from code; that blueprint has a parent class declared in code and i am usingtemplate to spawn.
The probelm is that the actor spawned doesn’t take input or movement, just like AddMovementInput(), and if i place the same blueprint actor on the level, it moves.
Can you help me understanding why this happen and how can i resolve?
Thanks in advance

hi KingDragonX AddMovementInput() is method from APawn or ACharacter so you cant simple use spawn via GetWorld()->SpawnActor(), so you need add spawnController
check AIBlueprintHelperLibrary.h
here is the code for spawn a new AI:

is super easy even you can add a behavior three, use GEngine->GetWorld() in order to get default world context



APawn* UAIBlueprintHelperLibrary::SpawnAIFromClass(UObject* WorldContextObject, TSubclassOf<APawn> PawnClass, UBehaviorTree* BehaviorTree, FVector Location, FRotator Rotation, bool bNoCollisionFail)
{
	APawn* NewPawn = NULL;

	UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject);
	if (World && *PawnClass)
	{
		FActorSpawnParameters ActorSpawnParams;
		ActorSpawnParams.SpawnCollisionHandlingOverride = bNoCollisionFail ? ESpawnActorCollisionHandlingMethod::AlwaysSpawn : ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButDontSpawnIfColliding;

		NewPawn = World->SpawnActor<APawn>(*PawnClass, Location, Rotation, ActorSpawnParams);

		if (NewPawn != NULL)
		{
                        //at this point Rama code remaind the same, yo if your new spawn actor dont have any controller, be sure to spawn one, and this is ALL
			if (NewPawn->Controller == NULL)
			{	// NOTE: SpawnDefaultController ALSO calls Possess() to possess the pawn (if a controller is successfully spawned).
				NewPawn->SpawnDefaultController();
			}

                        //here you can add a behavior three if you want, not necesary
			if (BehaviorTree != NULL)
			{
				AAIController* AIController = Cast<AAIController>(NewPawn->Controller);

				if (AIController != NULL)
				{
					AIController->RunBehaviorTree(BehaviorTree);
				}
			}
		}
	}

	return NewPawn;
}



check the coments in code, at this point the code is take from the header, but you may custom this, is easy!

cheers!

I missed the spawning of a new controller in my code, thank you :smiley: