Trying to get a random number to be stored and replicated across a network

Hi there,

So I’m trying to randomly generate an integer that will determine the order of events that happens throughout the course of the match, and I currently have it generating in the Game State. The problem is that each player then has a different random number, even if I try to store one and send it to all players. This causes different events to happen for different players when the same event should be playing. I have also tried setting this in the Game Instance and Game Mode (although I know the Game Mode cannot be referenced by clients).

I suppose I’m just trying to find where I can randomly generate a number and it be constant for all players.

Thanks in advance!

The integer that you are changing, is it replicated? If it is are you changing the value on the server and then sending it to clients the changed value? You can set the integer to rep notify which will create a function called OnRep_YourIntegerName. Now whenever you change the integer on the server this event will be called automatically on all clients with the changed value. Note that server will not execute this function locally so you have to manually call it for server.

With blueprint, just set your random number in a variable, set it only on the server, and set this variable to “replicate” or “repnotify”, as you need. It works for my project :wink:

Awesome thanks! Got it working now.