x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

nullptr instead of AController while BiginPlay on DedicatedServer

Hi!

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!

Product Version: UE 4.11
Tags:
more ▼

asked May 16 '16 at 06:26 PM in C++ Programming

avatar image

Yogi
53 5 8 9

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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:

 auto PC = NewController->CastToPlayerController();
 if (PC != nullptr) {
     auto UID = PC->PlayerState->UniqueId;
 }
more ▼

answered May 20 '16 at 05:11 AM

avatar image

Yogi
53 5 8 9

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered May 16 '16 at 07:40 PM

avatar image

Zhi Kang Shao
496 9 11 30

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question