Custom AIController called twice and GetPawn()==NULL
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
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
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????
Okay, I solved the problem in this way (maybe can help someone):
I understood also that Possess is called before of the controlled pawn's beginplay() so pay attention in anycase (I solved initializing things in constructor or in SpawnActorDeferred.
Still i don't know why BeginPlay was called twice but in some way I managed the problems.
answered Apr 08 '19 at 01:18 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here