Instanced static mesh component replication

Hello,

in my project I want to spawn many actors (100.000). Without instancing it is not possible to do it right, because there are too much triangles and it loads very long, while creating the actors.

I see only one method to resolve it. The instancing.

The Problem is that I use replication in my project, but replication with instancing actor components doesnt seem to work. The Client cant see the instances. Without replication every game instance spawns the mesh instances on different locations. (I spawn the mesh instances on random locations in a range).

Can anyone help me with spawning a lot of actors with replication and collision?

Thanks for your help,

Markus

Hi, if you want to use instancing, then AFAIK you would need to manually sync them. So if you want to place those instances randomly, then one option might be to use a seed and only send that to the client and place those instances locally on client and server. Otherwise you could send all the transforms of all the instances from the server to the client and place instances with those exact transforms on the client (if you want to also make changes to them during the game, then make sure to add them in the same order on the client as on the server). But keep in mind there that you can only call the same RPC twice per frame and there is a limit on the amount of data you can send through an RPC at once (don’t know whether that is something from the RPC or just the bandwidth limit from the config files). And repnotify might also give you problems when trying to replicate an array of 100.000 transforms…

Thank you for your answer.

Can you give me an example screenshot of the first option or a deep explanation?

It would be very helpful.

I didn’t actually try using a random stream and seed before, but here’s the doc Random Streams | Unreal Engine Documentation

So basically as I understand it, if you set a seed then you will get the same “random” values every time. So you then just need to send the seed you want to use from the server to the clients and then use that to generate the random transforms.

I tried this method and it works, but because of the seed the spawns are every time the same. Therefore I used the function “Seed Random Stream”. So everytime the function is used, it updates the random spawns. But then there is the same problem again, the spawns are different on the server and client. I call this function on begin play, so the Server and the Client execute it, I think thats the problem.

Here you can see the Seed logic…

I think the real problem is the following…
I want that the server generates random floats, when the game beginns. The other clients should access these random floats and do not generate own random values. Also clients, who joins the game later sould access the variable, which the server sets at the beginning.

You forgot to set the random seed.

This prints the same values on server and client. It’s not totally random since you have a limited number of integers and therefore you have about two billion combinations to choose from, but for the player it should feel like random.

329180-annotation-2021-02-08.jpg

The objects spawns at different locations on client and server…

329249-1.png

You could try

(-) make sure that actor is replicating
(-) try to print the result of random float in range from stream on server and client and compare the results

The actor is replicated.

I’ve set the for loop to 0 and 0. So there have to be one value on server and client side.

It prints the correct value on server and client, but in addition an extra value…

329301-3.png

Thank you for the effort and your help, I’ve found the issue.

I had to spawn the actor on the server. RPC Run on Server