Hello!
I have been fighting with this one a long time. Basically, I have a tool that allows players to draw into air by creating an Actor that has Instanced Static mesh component. When player is holding the trigger, new instances are added. This works great in single player game, but problems arise when I need to have this working in multiplayer.
There are approx, 100-1000 mesh instances in one drawing. If I replicate array normally, the clients will start lagging so much that playing is impossible until replication is finished. What I tried to do is putting all new instances to array and after 1 second, move all stuff from array to replicated array that is send to client, so the payload is much smaller for server, but I am having problems implementing that. Also, that system might have problems because game is Drop in / Drop out. So eventually, the replicated array has lot of stuff and newly joined players would try to replicate the whole array and we are back in square 1.
In Attachement is the code from the crucial parts.I explain them here:
Function BeginPlay:
We set the timer on. Timer runs functions SendJointBulkToReplicate and SendStrokeBulkToReplicate
Function Update:
Runs every tick. In this function, We are adding all the new strokes to NON-replicated array. If we are server, then we just draw them to world.
Function SendStrokeBulkToReplicate
We add all the stuff to replicated arrays and then clear the array so we can have new stuff in there.
Functions** OnRep_AddStroke** and OnRep_AddJoint
These are run after the** ReplicatedStrokeTransforms and ReplicatedJointTransforms **are updated. What I try to do there is to add instances that are yet to be added.
If I play this as a client, I can paint normally maybe 1-2 seconds and after that I get more and more lag. The more I draw, the more lag I starting to get. I thought that Array replication in Unreal is clever enough to replicate only new changes to array, not the whole array?
Any help how would I need to tackle the problem I have? I am even willing to pay for the help and guidance. Thanks!