In my project I have a playerPawn (already in the world) and an enemyPawn which should be possessed by AI when I spawn it into the world. enemyPawn is a c++ class based on Pawn, then i created the related blueprint. The problem appears when i spawn the enemyPawn and from myAiController i try to GetPawn(). GetPawn() returns NULL also if the enemyPawn was already created. The funny thing is that for some reason the beginplay function of myAIController runs for a second time and in that case the GetPawn() is not NULL.
I think everything is set correctly :
Pawn section of enemyPawn
This is my CustomAiController derived by AAIController
In my Enemy constructor i also added this two lines
AIControllerClass = AMyAIController::StaticClass();
AutoPossessAI = EAutoPossessAI::PlacedInWorldOrSpawned;
but i don’t think they are strictly necessary
I spawn the enemyPlayer from the gamemode (but it is the same if i spawn it everywhere else) through this instruction
AEnemy* enemy = GetWorld()->SpawnActor<AEnemy>(EnemyClass, FVector(600.0f, 0.0f, 0.0f), FRotator(.0f, .0f, .0f));
Do you have any idea why i get null the first time? and why beginPlay of MyAIController is called twice?
I also made an experiment in a new project with just a pawn, CustomAIController (that check if getPawn() is null otherwise it prints the name of the pawn) and an actor who spawns 3 pawns and I printed the result.
Can you solve this mistery???