Get Controller ID

This question seems so stupidly simple I was amazed I even needed to ask it. I’m working on a game that has local multiplayer. We have a functioning Blueprint set up to spawn the appropriate number of players, and on each “Create Player” function, there is an input called “Controller Id.” I assume this is the player’s index number in the game. My question is how I can get that ID number within the player blueprint class. Or alternatively, define an index value manually in the multiplayer setup Blueprint and cast that to each player.

Our game has a HUD that has elements such as health and ammo that must be assigned to each player manually. We have the input for those things ready to go, we just need a way of accessing the player’s index number to plug it in. So a more general version of this question would be how do I get an individual player’s index?

“The ID of the controller that the should control the newly created player. A value of -1 specifies to use the next available ID” (didn’t know that myself :stuck_out_tongue: and thats why i always recomand to look in to API refrence even to blueprint users)

You don’t need player index to associate HUD with PlayerController, they will refrence eachother automaticlly

From HUD:

or even:

From PlayerController:

So you don’t need to play with ids just set HUDClass in PlayerController and engine will set up everything for you

1 Like

That’s exactly how it’s already set up, and unfortunately it doesn’t work. Here’s the function that changes the health value in the HUD which the HUD class then uses to display the correct number of health bars.

The issue here is that the Player Index slot on Get Player Controller only affects the first player (Index 0). If it’s set to 1 or 2 or 3, it affects the second, third, or fourth player respectively. The only solutions seem to be either somehow getting the current player’s index and feeding that value into the integer slot, or using something else as the object for Cast to MiningPodHUD (though I have no idea what).

Thats not exacly how i said, if it was you would not need to get Player Controller at all, where this function is?

Also i recommand you to get pawn and controller varables from HUD class, insted of sending to class, you only duplicating data this way

1 Like

How exactly would I got about doing that? I need the names of specific functions or something, I’m completely stumped.

Okay, so I’ve figured out (through much headache and tedious research) how to call the player class variables directly from the HUD class instead of casting them from the player to the HUD. Basically it involved making those variables public and then doing a cast in the HUD blueprint, but because I had to cast it, I’m running into the same problem.

Now instead of changes to any player affecting only Player 1’s HUD (which is what it was doing before), changes to only Player 1 affect everyone’s HUD. So actually it’s more like exactly the opposite problem from what I had before.

The source of the problem is that in order to get those variables into the HUD class, I seem to HAVE to cast something, somewhere. And whether I’m casting to the HUD blueprint from the player blueprint or to the player blueprint from the HUD blueprint, it still requires a Get Player Character function, which still has that index pin, which is still set to a fixed integer value.

So I either need a way to get the player’s index, or a way to move the variables from the player class to the HUD class that doesn’t require any casting (or at least that doesn’t require use of Get Player Character). Does anyone know a way to do one of these things?

Your going about this the wrong way. All you need to do is make the variable editable in your character blueprint by checknig the eye. Then within your hud blueprint do a cast down to the variable you want and then update your hut from that variable.

Your hud is ALWAYS going to be your local controller. Multiplayer games and dedicated servers have no concept of anything that happens on HUDs. They only exist locally on the player that owns then. The other players can not access other players huds ext.

Here’s an example of getting a index of inventory items thats contained within my character blueprint doing this all from a HUD.

I gived you link to funtions, they are binded to blueprint

1 Like

That’s not working for me either. Here’s the relevant part of my current setup in my HUD class. The three variables I’m getting from the cast control Draw Texture functions later in the graph. As you can see, my Get Player Controller call doesn’t have a blue Target pin, but an integer pin.

Also, this is a local multiplayer game with no networking (at least not at the present time), so everything is being handled on one client.

EDIT: I’m also working in Unreal 4.2.1, if that affects anything.


Does anyone else have any other suggestions at all on how to get this working?

Use “Get Owning Player Controller” in your HUD Blueprint to get the correct player controller associated with that HUD.

From there on you should be on the right track with the rest of your Blueprint.

Also: You should seriously update to the latest version of UE until a few weeks before your release. The engine is still heavily being worked on and a lot of bugs get fixed with every new release.