I’m trying to get the character controlled by the given APlayerController in the AGameMode::PostLogin function.
But APlayerController::GetContolledPawn, as well as APlayerController::GetCharacter returns… Nothing
Is that normal ? How can I get the pawn owned by the APlayerController ?
When I play in editor or standalone mode I do see “Testing” printed to the screen. Since you are trying to get the pawn, you’ll want to make sure that you are casting to the pawn class so that the cast will succeed. Let me know if this helps.
I copied your code into my game mode and “Pawn exists” printed in both Standalone and PIE modes. What result do you get in PIE mode on your end? Do you have the same result in a new project with this same code? Additionally, can you provide a copy of the project where you are having this problem?
Could you explain the steps you used to reproduce this in a new project? I copied the code from your PostLogin function (changing AAInvadersAvatar to ACharacter for the code to compile) into a new project . In stand alone mode it printed that both the pawn and avatar exist.
Yeah sure :
We created a new project, then a ACharacter based class (we tested in c++ and in blueprint).
Then we created a new C++ GameMode, copy paste the code, and run.
And it does not work… Now we just try our project on 4.11 preview 7, still the same problem.
I may not be following the steps correctly, I’m not seeing pawn and avatar set properly in PIE or standalone.
Create a new project
Add Class based on Character (MyCharacter)
Add Class based on GameMode (MyGameMode)
In MyGameMode.h I add void PostLogin(APlayerController *NewPlayer) override;
In MyGameMode.cpp I copied the function you posted earlier, changing reference to InvaderGameMode to MyGameMode and changing references to AInvadersAvatar to MyCharacter
In MyGameMode.cpp, also add include statements for MyCharacter.h and Engine.h
After compiling, I set GameMode Override to MyGameMode
At this point when I PIE I see that the pawn exists but the avatar does not. Is there a step I’m missing or something I’m not setting as you are in your project? Let me know where my steps differ from what you’re doing in your project.
Could you please provide the project that you are using when you are experiencing this error, as we have been unable to reproduce it on our end. Go ahead and zip up your project, upload it to dropbox, and provide a link. You can PM me the link to download the project on the forums: https://forums.unrealengine.com/member.php?160394-Sean-Flint
After some investigation, it seems the reason that you are seeing your pawn and avatar not exist in standalone is because post login is being called before your avatar exists in the game. In PIE, a copy of your avatar is created initially, which is why you are seeing different results.
This is an order of operations issue, and in order to solve it you’ll need to move your code over to a function that will be called after the avatar exists in the level.