nullptr instead of AController while BiginPlay on DedicatedServer
I perform ClientTravel(Address, TRAVEL_Absolute); for connect the Spectator to the Dedicated Server, Pre and Post Login methods pass successfull, and after this was call BeginPlay on the dedicated server I invoke AController * GetController(), but I get nullptr. Why I have got nullptr instead of AController?
I do this for that would have get FUniqueNetId. So if exists some another way without using APlayerController in order to get FUniqueNetId, it will be great.
Thanks for any advice!
asked May 16 '16 at 06:26 PM in C++ Programming
I resolved my question. When Pawn is spawn, First invoked BiginPlay, and only after that the Pawn gets the controller after that on the client invoked OnRep_Controller and PossessedBy on the server. So for using controller I have to override PossessedBy. In order to get FUniqueNetId I use following code:
answered May 20 '16 at 05:11 AM
What kind of actor are you calling GetController on? A pawn? Something to keep in mind is that pawns and controllers may not be replicated over from server to client at the same time, so for example it may happen that a pawn is replicated over to the client, but the player controller isn't replicated over yet. Then the pawn's controller will be null. The controller will replicate over eventually but there may be some delay.
A neat way around this is to catch the exact moment at which a pawn's controller is replicated over and then do your logic that requires the controller. You can override APawn::OnRep_Controller for this. This gets called on the client (but server too possibly so take that into account) whenever the Controller value changes, so if it becomes non-null you know the controller has just been replicated over to the client.
Follow this question
Once you sign in you will be able to subscribe for any updates here