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"

PlayerController on Server and Client

In a multiplayer game, there is a copy of a player's PlayerController on his machine and on the server. I'm a little bit confused on how to tell whether functions on the PlayerController are called on the server or client (or both).

PreClientTravel() has Client in the name so I assume this is called only on the client?

What about other functions on the player controller? Are they called on both the client and server? For example, BeginPlayingState() UnFreeze() ChangeState() PostSeamlessTravel()? How do we know if they are called on both the client and server, server only, or client only?

If it doesn't have "Server" or "Client" in the function name is it assumed that it's called on both server and client instances of the PlayerController?

Product Version: UE 4.18
more ▼

asked Mar 12 '18 at 04:45 PM in C++ Programming

avatar image

48 10 12 19

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

The function can be called on both the server and the clients, but where it will be executed it depends on whether the function is RPCs. Non-RPCs functions are executed where they were called. You have the RPCs function marked with the UFUNCTION() macro (see in the declaration) in which you have:

  • Server - a function called on the client, but executed on the server.

  • Client - a function called on the server, but executed on the client.

  • NetMulticast - a function called on the server and executed on the server and on all clients.

In addition, whoever calls this function is also important. It's best to see the table https://docs.unrealengine.com/en-US/Gameplay/Networking/Actors/RPCs. Usually, this function will have a server or client in the name. Read also descriptions of functions.

The PreClientTravel() function is not RPC (it will be executed where it was called) is called in ClientTravelInternal(), which is RPCs (Client type):

  • If you call the ClientTravelInternal() function on the server, this function will be executed on the client that owns this actor.

  • If you call the ClientTravelInternal() function on the client, this function will be executed on the client that owns the actor.

So where the ClientTravelInternal() function will be executed, the PreClientTravel() function will also be executed there.

To divide the code into a server and client, you can use:

 if (Role == ROLE_Authority) // or if(HasAuthority()) 
     // will execute the Server
     // will execute the Client

more ▼

answered Mar 12 '18 at 11:01 PM

avatar image

341 2 7 5

avatar image Roi Danton Jun 16 '18 at 04:41 PM

Thanks, the distinction between calling and execution makes your post one of the most comprehensive explanations for networking! (unfortunately upvoting doesn't work for me)

(comments are locked)
10|2000 characters needed characters left
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