Part 3 Replicating functions

Back to main post

Note: In the documentation the blueprints are changed with the different steps. I am building new versions each time:

Space bar = MulticastSpawn
p = Run on Server
o = Run on owning client

Note: In this example the blueprints ar build in the character. The character lives both on the server and the client. So that is why, a function can by activated on the server by an action on the client.

From the documentation: Pawns (including Characters) will also exist on the server and on all clients, and can contain replicated variables and events. The decision of whether to use the PlayerController, the PlayerState, or the Pawn for a certain variable or event will depend on the situation, but the main thing to keep in mind is that the PlayerController and PlayerState will persist as long as the owning player stays connected to the game and the game doesn’t load a new level, whereas a Pawn may not. For example, if a Pawn dies during gameplay, it will usually be destroyed and replaced with a new Pawn, while the PlayerController and PlayerState will continue to exist and will be associated with the new Pawn once it finishes spawning. The Pawn’s health, therefore, would be stored on the Pawn itself, since that is specific to the actual instance of the Pawn and should be reset when the Pawn is replaced with a new one.

So it is better to use Playercontroller?

Step 1 Multicast (Spacebar)

The multicast only spawns to the clients if it is activated on the server.
So on a dedicated server how to activate this function?

Step 12. Graph shown is on the character

Step 2 Run on Server (key p)

Works on the Dedicated Server (local). Important that spawn actor is set on replication!

Activate fire on client and show on al clients. Graph shown is on the Character

Run on Server in combination with replicate is an important option with dedicated server, because you only have acces to client. From the documentation: The core of the networking technology in UE4 is actor replication. An actor with its “Replicates” flag set to true will automatically be synchronized from the server to clients who are connected to that server. An important point to understand is that actors are only replicated from the server to the clients – it’s not possible to have an actor replicate from a client to the server. Of course, clients still need to be able to send data to the server, and they do this through replicated “Run on server” events.

Stap 3 Run On Owning Client (key o to print inventory)

Explanation in my own words;

  • Character lives on both client and server
  • Variable Inventory lives on the character, so is accessible on both server and client
  • Triggerbox is in the level.
  • The character enters the triggerbox.
  • In the code (switch Authority) the events Add Item and Remove Item is only activated on the server. That is why when using a dedicated server the print string (in events Add Item and Remove Item) does not show. With a dedicated server only the clients have an graphical Interface.
WrapUp Part 3 video

I tried to get the Inventory printed on the client, from the level blueprint of the level.
This by connecting a print event to the Remote pin of switch has Authority.

Trying to print on the client

Text is printed on all clients. And it is the wrong text. So it looks like all clients are connected to the remote pin on the switch. Although it is a specific character which enters the triggerbox? To be continued.

Share Button

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.