So I made this setup that is at least working. But it is not pretty.
There are some things to keep in mind. The buffs are very basic, I don’t know what yours looks like. The buffs are also just a name variable, since I use data tables which is holding all the data. The way I set it up assumes that you want the server to handle the modification of stats and the clients only gets to do FX. Importantly, I am not sure if I would use this setup if you want the clients to handle the buffs.
So, the setup:
(obviously the remove buffs event would need more work in practice but as far as disabling fx, this is enough).
The client sends the buffID they wish to apply to the server.
The server adds the buff to the array, causing it to update to clients. The server then performs whatever logic is needed to apply the buff values to variables. I my case simply:
Now to the heart of the problem. The client will receive the updated array without knowing if buffs were added or removed. (or even modified, but that is not taken into consideration here).
So we store the particle systems in a struct together with the buffID, in an array.
Now when the repNotify happens, we compare each buff in the new array to each particle systems array.
If there is a match, that particle system has already been added to the list and we don’t have to do anything. We set a flag and break the latter loop.
If there is not a match, that’s a new buff and by getting the buffID, get the particle system corresponding to that buff from the data table, and add it to the array.
- I now notice there should a node after TRUE of the branch, setting the bool “match” to false for this to work correctly.
But another possibility is that a buff was removed. If that is the case, we will not detect the particle system that lingers in limbo using the above loop. We also need to compare each particle system to each buff.
If there is a match, the particle system has the corresponding buff running, so we can set a flag and break the latter loop.
If there is not a match, there exists a particle system that does not have a buff running. That particle system needs to be removed.
Now, because we can’t delete elements from an array while it is looping, we need to add its index to another array, practically marking it to be removed.
When all that is done, we loop through the marked indexes, delete the particle systems and removes the index.
To save on loops, you could first check which array is longer and run the appropriate system instead of both.
Using this, clients and server see a particle effect when a buff runs.
Only one particle system per buffID is spawned (even if there in this setup is no limit on actual buffs of the same buffID).
If clients are out of net cull distance, when they get inside net cull distance a particle system is spawned for each buffID.
Hopefully someone who worked with changing replicated arrays can give some pointers on how to do this better. well, I hope it helps even if its just a little bit.