ok so im just playing around, i a LIGHT BluePrint that is placed in the map…
With the actual light being replicated, and the light is trigger on/off when player enters the room.
Then all is trigger fine, the main control is here where i want the light to stay on if there are more then [1] players in the zone, if the last player leaves then switch it off…
Which i have accomplished but want to know if there is a better way?
There’s a trigger zone that keeps the light on whenever any character is in it
The light state is replicated to everyone in the level
I would do it like so:
Make the “light is on” property be replicated (easiest just to replicate the entire light.)
Create a list of actors currently in the trigger zone, on the trigger zone object
Inside the OnActorBeginOverlap() callback, add the overlapping actor uniquely to the list of overlapping actors
Inside the OnActorEndOverlap() callback, remove the ending actor from the list of overlapping actors
In both case 3) and case 4), i e after each time you mutate that array, set the “light is on” flag to “true” if the size of the array is greater than 0, else false. It’s OK to update the flag to some value it already has.
The logic for 3/4/5 only needs to run on the server. The list of actors in the trigger does not need to be replicated (the trigger doesn’t even need to be replicated.) Only the light state matters.
yes that are the correct requirement, my actual light is replicated.
That is a good suggestion yes adding each player to and arrey list.
But would’t that be more memory transmitting in bandwidth.
As in my case i am increasing a replicated variable “GlobalIsPlayerOnMarker” add +1
every time a player is in the zone,( only replicating the +1 on the server) and removing -1 when a player leaves so i only turn the lift off
of the Variable is ==1, meaning when last player leaves in the zone
First: You only need to keep the list on the server. As I said, only the light state needs to be replicated.
Second: players go into/out of areas quite infreqently (compared to “firing weapons” or “general movement,”) so even if you did replicate this list (which you don’t need to,) it probably wouldn’t be a big deal.
The draw-back of a counter is that if you ever have any bug, the counter is off forever. The list (or set) will self-correct if you accidentally call “add” or “release” more than once for the same player.