Get players controller index in multiplayer

So I’m trying to create a dev tool (only i have access to) so i can debug and affect different things in game, all going fine except one seemingly complex issue, hopefully theres a simple solution.

For example, I want to set a player to be invisible. It’s difficult to know which player is which index (I’ll post the code example so you can see where I’m talking about.)

Current Findings:

  • Player 0 is self for each player
  • Player 1, for the host is client 1, for each client it’s the host
  • Player 2, for the host is client 2, for each client it’s the other client
  • I haven’t tried to see what happens with 4 players yet

You can see in the code example how i circumvent this with a switch has authority and setting the index to 0 for host and 1 for client so that as the host i can turn myself invisible. But as a client i want to be able to do the same stuff, which works just fine using RCP events (server to multicast) but it only affects the host - identifying the player index is tough as each player seems to have a unique sequence of who’s who…

The ultimate idea is to be able to select the player to be affected in the ui, then select what you want to happen


The idea was to set the affected player when clicking the player button
image
and then passing that player index along to the RPC logic

Interestingly, as a side note becuase it may provide some insight, the correct player is found and affected via the flying example (and godmode/noclip) but not with invisibility (at least as host, although thats because the host has access to the players in the server) ← i’ll post another screenshot of how i’m retrieving whos who atm, which works on host but not on client:


image

How would I be able to retrieve this as a client?

So if anyone can help me figure out the best way to do this or identify which player index is who (maybe theres a known rule it follows) i’d be very grateful!!

Use PlayerState PlayerID for a networked player by player identifier

do you mean like this?

I’ll give it a go

Hmmm… Sort of got it working in the end, but i have a different issue now, it works fine for the host but when client tries to do it, it fails here (doesnt get to check 3 print string)
image
image

Can the client not call a custom event that calls a server event that calls a multicast event?
I feel like ive played trial and error for hours, ive put the switch has authority everywhere but if someone knows that’d be great because I get really confused with replication.

I think you would benefit from reading through the network compendium
UE4 - Network Compendium

1 Like