So I have a relatively simple problem and I’d like some advice on the best way to solve it. I have a server function in my player pawn. The player presses a button in the UI and it calls the server function, and everything works.
I have a two-player game, so inside that server function, I want to disable input for both players’ pawns:
AMyPawn::PawnCode()
{ DisableInput(Cast(GetController())); }
What would be the best way to do this? I want to call this actual “PawnCode” function rather than just calling “DisableInput” somewhere; I’ve tried a few things with varying success:
1. First I tried to call PawnCode as a client RPC, before realizing that that will only execute on the owning pawn owned by the client who called it.
2. I tried calling PawnCode as a multicast RPC, but that gave me two issues: first, it called PawnCode twice on the client that called it. I thought that this was because I had a listen server, so it called it once for the server and once for the client on the server. But then I tried running it with a dedicated server and got an identical result.
Regardless of that issue, it didn’t even work for the other client. It disabled input correctly for the client who called it, but not for the other client, despite the fact that debugging shows that the PawnCode function was called in the other client’s pawn.
3. I tried getting every actor of the AMyPawn class and calling PawnCode on each one. This actually worked, but I feel like it’s bad practice and a waste of performance to use GetAllActorsOfClass whenever I need every client for something. Not only that, but this method also had the double-call issue, where it gets called twice for the pawn of the client who called it. Some more debugging showed that there are only two pawns, but PawnCode executes twice on the one owned by the instigating client.
4. I assume that I could use the gamemode or game state to get all of the controllers, get all of their pawns, and call PawnCode for each of them. But I feel like that couldn’t possibly be the best way to do this.
I’m fairly experienced with Unreal and C++, but very new to networking (yes, I’ve read this already). Clearly, I don’t have the best grasp on RPCs. I’d really appreciate any advice anyone has for this problem, and/or for the best practice in these kinds of scenarios. Thanks in advance!