How can a GameMode set a Variable in a Player Character? (Multiplayer)

My ultimate goal here, is to have each consecutive player to join a networked multiplayer game have a unique player number above their head… but right now I’d settle on just setting an integer variable in character that i could use for any number or things.

What I have:

  • A GameMode that has the Default Pawn Class set to a Character called HeroCharacter
  • HeroCharacter is a Character Class that has a Variable (Integer) called PlayerNumber. The Variable is set to Public.

I gather I need to use the Event OnPostLogin in the GameMode Blueprint to refer to the player controller (presuambly via the NewPlayer Output) that has just logged in, but I don’t know how reference the playercontroller in such a way that it can access the Variables inside the player character.

I’d like to have a variable inside the GameMode that simply increments as each player logs in, assinging the next number to each player.

Please and Thank you for anyone willing to help.

You should look into player states.

But for the answer itself. You need to properly replicate it to all clients.

This tutorial is quite good showing you the basics:

I watched the video, and did some more searching that led me to [THIS THREAD][1] and came up with this.

It’s not actually in the GameMode, though, it’s in the HeroCharacter Blueprint.

The custom event, AssignPlayerNumber, is then called on Event BeginPlay

It works as desired… for now.
Hopefully it will be useful for my other plans.