Disable input for a specific player in a multiplayer game

No, all players have their own controller.
On server machine, there is one controller for each player.
On client machines, only their own local controller exists. But it’s not a shared one.

Replicating controller index from a controller array which, I assume, is filled by GetAllActorsOfClass, is the worst of ideas. First, GetAllActorsOfClass does not have consistent order. But more importantly, client does not know about other clients’ controller, so GetAllActorsOfClass(Controller) on client always only return one controller : his own.

Even replicating the controller (as in, a variable of type Controller or PlayerController) is a bad idea because it will end up NULL on all clients who don’t own that controller.

Gamemode is a server-only class, and cannot replicate stuff.

Use GameState. It’s a singleton, replicated to everyone, meant to represent the current state of the overall game. Add a variable of type PlayerState to represent which player should have input. Mark that variable replicated with RepNotify. This will automatically generate a function OnRep_Variable. That function is called automatically whenever the underlying variable is updated and replicated.
From there, check if the variable’s value is equal to the local player’s PlayerState. If true, enable input, else, disable input. Something like this

1 Like