I’m still trying to wrap my head around replication but basically what I’m trying to do is set a variable (Terminal is being used) and replicate that to all the clients so that if a player is using said terminal they wouldn’t be able to interact with it.
The main problem is that I can’t get the ((In Use) event to execute, I’ve been stuck on this for awhile and I’ve tried everything that I know to get it to work. If anyone could help it would be greatly appreciated.
Hi, you need to set TerminalIsBeingUsed to be replicated, otherwise you only set it on the server but the clients will never know about that.
I can’t get the ((In Use) event to
execute
Try to put a print in there, you should then see that the server is already executing it. The RunOnServer events that get called by the clients will all be dropped, since only the owning client can call RunOnServer events on an actor, but the server also calls it, therefore there it will execute.
The next problem is that since the overlap happens on all clients, all clients will eventually execute OnComponentBeginOverlap and therefore enable collision on Widget and hoping that TerminalIsBeingUsed will be replicated to those clients before the overlap happens there will lead to unpredictable behavior. That means that before you execute the logic after the overlap you need to check that you only execute the logic on the client whose pawn overlapped (e. g. check that GetController of OtherActor == GetPlayerController with index 0).
I got the variable to replicate and it works now but is there anything I can use other than (GetPlayerController Index 0) for the overlap? because while it works for the first player, it doesn’t for the second player. I guess because the second player has a different index? or will this not be an issue if I was using two separate computers? though it makes it a little hard to test features.
Thanks for your time and comprehensive answer.
or will this not be an issue if I was
using two separate computers?
It shouldn’t make any difference here whether you play in editor with several clients, or have several standalone/several computers. GetPlayerController with index 0 will always return the local player controller. Further that is the only controller that exists on a client, all other player controller / AI controller do not exist on clients. But you could use some print nodes to see what is going on.
What you do need to do though, is always update TerminalIsBeingUsed on the server, that should happen regardless of GetPlayerController == GetInstigatorController (you could use a sequence node).
Yeah I don’t know why in my case it’s being so picky and making a difference here but I came up with a solution that fixed all of it but It’s probably super overcomplicated for what it needs to be, It works though.
I’m basically just setting a variable when a player overlaps so if another client tries to overlap while another player is, it checks 1. if your locally controlled and 2. if the overlapping player is the same as the first player to enter the collision sphere.
It seems to be working fine but again it seem super overcomplex lmao
I’ll keep messing around with it to see if I can get (GetPlayerController w/index 0) working, like you said I don’t know why it would matter if I was using two separate computers or not.
Thanks for the help though!
Two years have past and you surely have made a lot of progress since then but you could simply cast your actor to your player BP.
If your player actor is called “BP_Player” you would do :
On component begin overlap → cast to (other actor, BP_Player) → your function
this way, it will execute only if the actor that overlaps is a player.
I hope this helps