@Jorgy_M
Hey! When do you use GetControlledPawn
?
I’m just guessing here, but maybe the AI Controller lifecycle and the character’s initialization gets out of sync when dynamically spawning actors. This is why it works when you manually add the character. Like everything is already running correctly in order.
So maybe the AI Controller might not initialize correctly if the character isn’t fully ready at the moment it spawns and while “Placed in World or Spawned” usually works, in some cases, spawning dynamically requires additional steps to ensure the controller properly attaches.
Maybe try this in blueprint (i’m not really familiar with BP):
// Blueprint:
// After spawning the character
SpawnedCharacter->SpawnDefaultController();
You might need a slight delay to let the character finish its initialization. In Blueprint, use a Delay
node (e.g., 0.1 seconds) before calling SpawnDefaultController
.
Or make sure you override the OnPosses
and call corresponding data from there, with a delegate or something that actually works for you.
void AYourAIController::OnPossess(APawn* InPawn)
{
Super::OnPossess(InPawn);
// Your custom initialization code
if (InPawn)
{
// Do something here
UE_LOG(LogTemp, Warning, TEXT("AI Controller Possessed: %s"), *InPawn->GetName());
}
}
So again, this is just a guessing, without seeing any actual code you made.