Help with replicating Random Streams

Hello,
im building an online randomly generated map using Procedural Mesh Component, i tried to replicate PM Component but no luck,
so i decieded to use Random Stream and let the cleint spawn the map synced with server,
Unfortunately i wasnt able to achieve that, it seems like the servers and the cleints random stream is out of sync even when having the same seed.


this happens in Begin Play of the actor responsable for genrating the map, this actor is set to replicate.


i even tried to sequence some of the random settings, i thought maybe unreal change the assign order each time.

my question is, how to sync both server and cleints random stream, and have the same map layout by having the same random numbers? the map generation take up to 500 random numbers to make the final map.

First off you’re setting the same variable 3 times.
Secondly, have the server set the variables and replicate them to you.

1 Like

hi,
thanks for replying.

about the variable set 3 times, its just a desperate move by me to fix the issue, i thought maybe unreal change thier order of excuting the random pure function each time, so i sequenced it to try forcing unreal a fixed order of retreiving the random numbers, for the sake of Random Streams sequence of random nymbers.
below was my normal setting.

about your suggestion to make the variables on server and replicate,
unfortunately thats not possible since my map generating logic nest the same function inside of it to make multiple generated paths, and most of the variables used are local vars inside of that function.

Hey,

So yeah you will need this seed value to be the same here and then also the sequence of events to be the same otherwise the order at which it pulls the numbers from the stream will be different.

just to add another try.
i tried to replicate the Random Stream itself but no luck, like below

below just to show that i replaced all normal random with stream randoms

hi,

yeah sequence of function code is not changing, i dont even call any other actor except a Function Library.

Could it be this happening because of im trying on the same device?

I wouldn’t expect that to be the case, can you try printing the seed of the stream at the start and then just running a series of Print Strings grabbing a random value from the stream and checking if they are the same outside of the map logic.

1 Like

thanks @JakeSimpson for your debugging idea, i shouldve tried that the first thing.
below shows consistency in random outcome, and we can say the random stream is replicated perfectly here.
so the issue must be with the map logic, even though i ran out of workarounds to solve it, i might have to change the whole approach.

hi all,

i believe i found the issue, even though i havent found the sulotion yet.

i have a section in the map function that spawn actors, and not all actors are allowed to be spawned in a client, e.g. enemies, they are spawned only on server and replicate.

when i excluded this section, the map logic synced generation perfectly with client.
but with using that section the server and client seed get out of sync.

new question, does Has Authority node affect Random Stream?


below showing working synced generation after excluding actor spawning section


below showing the issue section

So its not that the Has Authority specifically is affecting the Stream but what is happening is due to the Pure nodes you have there.

With this section here on the Client you use the Bool to check whether to spawn which runs the Random Int in Stream. That bool is false so it continues.

Whereas on the server this returns true and therefore re runs the Random Int From Stream for each other pin you pull out from that node.

To solve this, cache the returned struct from the Get and use that instead of breaking it as you have there.

1 Like

thanks man for spotting the issue,
yes indeed, when there is a slight change of code between server and client the Random Seed gets unsynced.

this is the way i approached and thankfully its working.

replaced spawning, in the generator function, with a spawn array

==========

spawn after the generator function finishes


=========

thanks a lot Jake for your help, and please tell me if you have any note on my approach.

Yeah that looks great, happy to help @S3OD1 :smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.