Problem with setting a variable across server and clients.


I have this code in the character blueprint which is using authority to check whether its a server or client. When the Red Trigger Box variable (which is a local variable) is set to true by the player it calls the REDBOX function at the top which is multicasting the print string to everyone:

The result of this on a server with a server and two clients:


So the event which prints the string is being called on the server and both clients which seems correct.

When I change the original code to this, where it is no long printing a string it is setting a variable from 0 to 1:

When I play the game and call the REDBOX function from one of the players the Red Trigger variable does not become 1 for everyone, only the player which calls the function.

Why does the SET Red Trigger work differently to print string? Is there something I’m missing to be able to set the Red Trigger variable for everyone on the server?

A replicated variable should ONLY be set server-side. In your REDBOX you are attempting to just set the variable on all individual clients client-side and that results in the variable not being replicated.

Thanks for the reply GarnerP57,

My understanding is if its a client it runs the event ClientUpdateRedBox which is set to RunOnServer. The REDBOX function is then called by that which is set to multicast. So is a client not telling the server to run the function REDBOX and then the server is running it for everyone. I’m probably not understanding this correctly.

What would you do to change it so that every client gets the updated Red Trigger variable?

First of all you should avoid using Tick unless it is absolutely necessary and even then it should probably not be called every frame. The quick and dirty fix for you would be to remove the Multicast from the REDBOX event so it is only set on the server.

I’ve tried removing the multicast but it still doesn’t replicate the variable to all the clients. Should the variable be in the character blueprint? If its one variable that needs to be consistent to everyone on the server and can be changed by any of the clients should it be somewhere else like a game state class or would that not really matter?

Not everyone on the server will be able to see every BP, for instance your controller BP is not shared between clients, your character and playerstate tends to be good places to put character related stuff that you need your character to replicate for everyone to see, like their HP faction and name and all of that this way everyone can see what player 2’s hp is, and if it is something that needs to be replicated from the server to everyone that is then I would look at your level bp or game instance.

It would be quicker to explain if you could tell me what task you are trying to do so we can get rid of the tick node altogether.