Replicating a random int in multiplayer

Hello!
I have a power up that i can spawn. This power up spawns with a random material, and light color. This is chosen with a random integer with the range of 0 ->4. This works 100% in single player, and server side. However the client seems to re do the random integer, and thus spawn with a different material, and light color after i set the variable to replicated.

How can i set this integer to be the same for both client, and server side?

1 Like

Thanks man, worked like a charm. I had a feeling it was being randomized across all clients, just new to the engine, and didn’t know how to fix it.

Hey,

You’re doing the replication wrong. You want to set the variable to a repnotify, rather than replicated. Then next you want to set the random int on the server(not multicast).

Then go to functions and there you see a newly created function called OnRepSomething and in that variable do the part that comes behind the int set.

Reason why it doesn’t work is because you’re doing the random on all clients rather than the server.

Thank you! This did the trick for me as well. Rep Notifies are powerful!

Worth noting that if you’re using Random Int in Range to spawn another actor or set a child actor class, that actor needs to have replication checked to be visible to the client. Took me some trouble shooting to figure out.