x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: Not Selected
Tags:
more ▼

asked Oct 10 '14 at 11:32 PM in Blueprint Scripting

avatar image

ZachCox
6 5 7 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

5 answers: sort voted first

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.

Marc

more ▼

answered Oct 23 '14 at 03:13 PM

avatar image

mkamradt
294 15 136 34

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Kismet/UGameplayStatics/CreatePlayer/index.html

"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 :p 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: https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/GameFramework/AHUD/GetOwningPlayerController/index.html or even: https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/GameFramework/AHUD/GetOwningPawn/index.html

From PlayerController: https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/GameFramework/APlayerController/GetHUD/index.html

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

more ▼

answered Oct 11 '14 at 01:17 AM

avatar image

Shadowriver
35.8k 927 169 1105

avatar image ZachCox Oct 11 '14 at 03:19 AM

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.

alt text

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).

bp.jpg (134.0 kB)
avatar image Shadowriver Oct 11 '14 at 02:33 PM

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

avatar image ZachCox Oct 11 '14 at 07:24 PM

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

avatar image Shadowriver Oct 12 '14 at 02:57 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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?

more ▼

answered Oct 12 '14 at 05:14 AM

avatar image

ZachCox
6 5 7 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

alt text

sc1.jpg (89.8 kB)
more ▼

answered Oct 12 '14 at 02:26 PM

avatar image

Toom
166 4 8 27

avatar image ZachCox Oct 13 '14 at 03:02 AM

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.

alt text

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

bp2.jpg (272.5 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Bump

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

more ▼

answered Oct 13 '14 at 11:09 PM

avatar image

ZachCox
6 5 7 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question