Remove Instanced Foliage at Runtime; Networking

Hello all, I seem to be stumped on how to get this working for network replication. Right now I have a level that has instanced foliage using a foliage spawner and everything seems to run fine on the Servers side but when the client tries to remove an instanced mesh it does not remove it. I have a feeling it has something to do with the instanced index for each client being different which is why it’s not removing it, correct me if I’m wrong though. I use a line trace to check and see which tree is being hit then remove it and place a static mesh in it’s place to make it look like the tree was cut down.

Any help on figuring out the client side problem would be well appreciated.

I believe I figured this out. I made the instanced index for the foliage components OnRepNotify instead of just replicate and then within that function I called the remove instanced static mesh node and linked the index to that. Not sure if it’s the most performance way to go about it but it seems to do the trick until I can find another way to do it differently.

Your foliage instanced static meshes will probably not be replicated, so each client has a separate copy of the trees themselves.

I expect the indexes should be identical between server and client so try this. The server calls an event which is multicast.

That multicast event has an integer parameter, which is used to remove that specific instance on each client independently. (Multicast Event with Integer Parameter —> Remove instance node)

If that doesn’t work, I’d assume that the server and client don’t have matching indexes for your foliage. If that’s the case, repeat the previous multicasting but do this instead:

The multicast event has a location (vector3) parameter instead. When called, each client uses that location to do a sphere trace (even better, there should be a “find all instances within radius” node for instanced static meshes), and remove the one which is found that way.

Furthermore, to prevent accidentally removing the wrong instance, you can do a vector = vector boolean comparison to make sure the instance you are removing is in (approximately) the exact same spot.