Download

How to replicate "random stream"?

I ran into a problem while replicating my game, I have no idea how to replicate this code, namely the random spawn of items on the map. I am new to UE4, so I will be glad if you can help me!

Blueprint: Screenshot by Lightshot

You need to RPC to the Server and get it to execute the Random node. Then assign the result to a replicated var that clients all have access to. :wink: So, don’t use random nodes client-side for core gameplay, only for incidental things like Visual FX. BTW: If you’re learning this stuff through Video-Tuts / Docs, try instead to take projects apart (see sig). :wink:

Yeah the Server needs to Spawn items. When the server spawns things, it will replicate the spawning to each client.

The same approach applies to picking up and dropping items.

What the others said about spawning.
About the thread title: dont replicate the stream, but the seed and initialize the stream on everyones machine with it once at the beginning. everyone will then generate the same random numbers in the same order whenever they request a random number from the stream. so in your BP dont create a random seed (SeedRandomStream), but set the seed to a specific integer (SetRandomStreamSeed) - the one you replicated. the number used as a seed should be picked by the host initially, either randomly (e.g. millsecs) or as a UI setting available to the player hosting (“lets play seed 12347 again, it was fun last time!”).

Thank you, I thought for a long time how best to do this.

https://forums.unrealengine.com/core/image/png;base64

I tried to do what you said, but as far as I understand, nothing worked for me. I hope you can help me

Blueprint: Screenshot by Lightshot (It’s actor)

Are you initializing the seed in the game instance?
Screenshot 2021-01-22 131454.jpg

If you still need help, attach the image here on these forums as that site is blocked wherever it is.:wink:

Here yah go.

You need to say more about how its not working, otherwise its hard to help. So have to make some educated guesses for now. But first, when something isn’t working, its good to simplify things. So I suggest getting rid of all seed + stream logic, and focus on using a simple random int node in the ServerSeed code.

What I suggested above is this. Create a new Integer variable RandomInt and set its ‘Replication = Replicated’. Then drag RandomInt into the graph as a RandomInt Set node and connect that to ServerSeed. Then add a Random Integer In Range node, and supply 0 and 4 as before as the params, and then assign the return value from that to RandomInt Set. This guarantees that the Server sets the random number, and you can debug it easily in one place. Then, in the MulticastSeed code, drag RandomInt Get node into the graph, and connect it to the **Array **Get instead of what you have right now. Run it and describe what you see. Are you seeing spawns on player screens, or are you getting nothing at all…

If you’re getting nothing at all, you need to check where the ‘Begin Play’ is executing from. A good rule of thumb, is that an RPC needs to be executed from a Character or Pawn, that you the ‘player’ own. If that isn’t satisfied, the code isn’t going to work, and you’ll need re-evaluate the whole design. That is, unless Gamemode is actually doing the spawning. But since it only exists on the Server, it will only work there, not on Clients.

Up to now I’ve been assuming the 5 BP pickups classes, have replication unTicked… Otherwise when the Server executes this code, you’re going to get duplicates on the Clients, in addition to whatever the Clients spawn. But what’s the ultimate goal here anyway? Why are you doing spawns on the Clients, unless its non-game critical stuff like VFX for example. Most spawns are done on the Server, because the Server needs to know about the pickups, because the Server needs to control the health of the Clients, NOT the Clients (to avoid cheating).

The next thing to check, is whether the Spawn transform / location is valid. On the ‘Collision Handling Override’ setting on the pickups Spawn Actor node, choose ‘Always Spawn Ignore collisions’, as this ensures the spawns will always work. Its dependent on having the correct ‘Transform’ though. But since you haven’t shown what class ‘Self is’, its hard to know what the correct value should be.

One other thing, why not move the Make Array code to where ServerSeed executes. Or going further, just create a new variable called Pickups of type ‘class reference’ and set it as an array. Then add the 5 pickups classes to it and set it to replicated as well. See here… This is optional, but going back to simplifying things, it ensures everything is setup on the Server in one place. BTW: You may end up using a Repnotify for some of this code later, it just depends.

I tried to convey all the random logic to the character. Now I have synchronized the client with the server, but the server has two loops, but there are many more loot generation objects on the server.

if you watch the first seconds of the video, you will see how, after the client is loaded, another row of elements appears on the server.

I tried to do as you said, but the code only worked on the server side. Because of what I decided to transfer all the logic from actor to player. On the actor side, I left only the call to the player with the transfer of all the necessary data. On the character side, I did all the logic, and then created an actor with an object.

The screenshots show all the code:

https://forums.unrealengine.com/core/image/png;base64

ffe5e076affc7ac951a5a1e563346c3c9e5f6cfc.png

fec971f39b950847250b85f5b98677a40b800676.png

@PEV322

Not following what the code is about anymore, even after watching the vid (why spawn on a multicast?:confused:). So what’s the goal? :wink: Maybe someone else can help, or have a look around for a multiplayer template / tutorial that’s close to what you want.

I am trying to execute all the logic on the server side and then create an item for all clients with this data. I understand that most likely I’m doing something wrong, and using incorrect functions, that’s why I wrote here.

https://forums.unrealengine.com/core/image/png;base64

Still no idea of what you really want. Are you using a translator maybe? If so, post in your native language as well.:wink: Normally for pickups to spawn SPAWN ACTOR is only done on the Server NOT the Clients (Multicast is for Particle FX / Sound FX). But for it to work each pickup must have Replicates TICKED ON in BP_HealthPickups Class Defaults. That said, is this even what you want, IDK, I’m just guessing.:wink:

Yes, I use a translator to communicate with you, as I am not perfect in English.
Да, я использую переводчик для общения с вами, так как я не идеально владею английским языком.

Thanks for helping me, I now have synchronized spawn zones, but I ran into other problems, but I hope I solve them myself.
Спасибо, что помогли мне, теперь у меня есть синхронизированные зоны появления, но я столкнулся с другими проблемами, но я надеюсь, что я их решу сам.