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 player index of who pressed key

Hello,

I am trying to get the player index of who pressed a key for a local multiplayer game.

This event exists on an object, and when there is an overlap, it checks to see it is a player character, and if so, it gets the player index (player 1 or 2) and enables input for the object. alt text

This second event also exists on the object to allow the player to actually do the interacting. However, i run into the problem of not being able to get the player index of who pressed the key, so get player character is always index 0. I would need the player index to I can cast to that specific player, and in the case of this event, have the player pick up the object.

alt text

Any help would be much appreciated!

Product Version: UE 4.15
Tags:
1.png (219.1 kB)
2.png (98.9 kB)
more ▼

asked Mar 03 '17 at 07:51 PM in Blueprint Scripting

avatar image

erbmur
16 3 5 7

avatar image Shadowriver Mar 03 '17 at 08:58 PM

I never tried that as i didn't do any local multiplayer, but i think if you place input even in player controler the events will be rised only when owner of that contoller, i think the same might be with possesed pawn, so try it out.

Either way i notice something strange in first graph how you handle controller, you doing it in very wierd way.

Get Controller->Cast to MainGamController-> Get Controller ID->Get Player Controller->...

You getting controller, you casting it and for some odd reason you getting it's id to get controller all over again. MainGameController is already PlayerController as it inhrits from that class so you don't need to get controller again or even cast it to PlayerController, all pin that that are parents of the class MainGameController: PlayerController->Controller->Actor->Object will accept it, You only need to cast to highest class that you need, if you use PlayerController nodes only, you cast to PlayerController, if you use function inside your controller you cast it to your class, but from that cast you still able to use it as PlayerController so you don 't need to get or cast again, just once.

So you can use one that you got from Get Controller, the cast will fail if it's not playercontroller anyway stoping the execution.

avatar image erbmur Mar 04 '17 at 06:22 AM

Hi Shadow,

First off thanks for the reply. I am new to UE4, so i have taken into account what you said about the second image and have "removed the middle men".

As for my main question, if I place the inputaction in the character rather then in the object, then i would still need someway to pass the properties of the object through to the player character for him to be able to interact with it.

I guess I could create a variable within the character for intractable objects, but was hoping there was a way to get the information only when a button was pressed, not every time there is an overlap?

I'm guessing some kind of interface might be able to do the trick, but being new, I have not used them yet or know how i would go about implementing one, if it is in fact the right way to go?

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

1 answer: sort voted first

I fixed the issue.

Just set up a variable in the overlapped actor called "OverlappingActor" that gets populated if a viable actor is overlapping.

more ▼

answered Mar 08 '17 at 12:46 PM

avatar image

erbmur
16 3 5 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