How to reference each PlayerController from GameMode in Blueprints for a network multiplayer game

I am working on an online turn-based combat game (think pokemon) and I am trying to setup the HUD for each client to show each player’s stats such as health. I am also trying to set a flag on each PlayerController for whether or not it is that player’s turn to attack. I am getting “Blueprint Runtime Error: Accessed None trying to read property ~” when I try to reference the second player pawn or controller. Everything works as intended on the listen server client, but not the remote client.

I was hoping that somebody could explain in a general way how to pass properties between two remote clients and how to reference the PlayerControllers for those clients from the GameMode. Thank you.

you would need to add a reference of Player controller to your player state, and from Gamestate get PlayerArray which returns the playerstates in the game, cast it and retrieve the reference.

in your instance blueprint, there is an “OnPostLogin” event with the controller added in the game

Odd, i was sure i posted my suggestion on the switch turn. here it is again…i use playerstate to store the variables.

Even since question is answered, i feel need to make a remark that code on screenshot in accepted answer is kinda wrong.

The Owner (get owner function) of Player State class is appropriate Player Controller, so it always can be accessed on server or on owning client without any extra setup required.

Also if any of you need some help on blueprint multiplayer setup, msg me on forum.

Thank you. I did already see the Event_OnPostLogin in my GameInstance BP gave me a reference to the player controller that is joining the session.

This does actually answer my question, so I have accepted it. Thanks! However, I believe my actual problem is not what I had asked in my original question. My second player does not appear to be loading/spawning correctly and I am getting null reference trying to access it. I will post a new question if I figure out exactly what my problem is and I can’t fix it. Thanks again!

i think i got your issue. here is the gamemode setup i always bring up if i need multiplayer managment. this is from the multiplayer shootout. it assures you each spawned player has its own controlled pawn. i even make a BP for player start to keep things tidy and do an auto RcvReadyRespawn if im debugging (and dont want to wait for the onPostLogin to trigger it)

][2]

please note i forgot to link the controller from onpostlogin to the rcvreadyRespawn (i adapted it for the screenshot)

thanks, im still discovering how unreal works, so if i dont know any built-in feature, i create it to fit my needs.

Thank you for continuing to help out with this. I have been busy the last few days, so sorry I am slow with replying.

My problem seems to be that RcvReadyRespawn only fires on the server, but not the remote client. Could this be because I am just launching the level instead of using JoinSession and an OnlineSubsystem? For all my networking I have essentially copied the MultiplayerShootout example already, so you can assume my project is extremely similar. I do not call the respawn event from a custom PlayerStart. Should I? That does not seem to be the proper way to handle things. Like I said, my problem appears to be that OnPostLogin is only fired once for the listen server client and not at all for the remote client. This causes my remote client to spawn a default character at the remaining PlayerStart instead of spawning the character properly within RcvReadyRespawn.

Again, I am just PIE’ing into my level and skipping the main menu and the matchmaking create/join session stuff. I am doing this because I have not been able to get a Null or Steam OnlineSubsystem to work yet. You have been beyond helpful so far! Thank you!

Late to this party, but for the benefit of whomever might be looking this up, for any PlayerState you can call GetOwner and cast it to the player controller you’re using. For replication just make sure you put a SwitchHasAuthority.

Wow does this mean I could by default access client 1’s PC from client 2? I have been storing a PCRef on each players’ player state, which does essentially this, bc I did not think of just asking for the owning PC like this. But I was looking for a better way bc I thought “man i shouldnt be allowing any client access the PCRef of other clients arbitrarily, since all clients have a replicated PlayerState for each other client”. But looks like yeah you can just do that. Is this still how you would do this?

PlayerControllers don’t fully replicate, from what I’m told. PlayerStates and Pawns do, though.
So, since the PlayerController owns the network connection (again it just seems that way to me), you still have to go through the Server to communicate to a specific other PlayerController.