How to enable input for only specific characters?

Hey all,

I was wondering if there is any way to assign specific actions only to specific characters.

For instance, I have an Action Mapping (“Interact”) that only one of the three characters in my game should be able to use. In this case, “Interact” happens when the M key is pressed.

I’m creating a single-player game where the player can assume control over any of the three characters in the game by respectively pressing the 1/2/3 key.
What happens now is that no matter which character the player has possession over, once the M key is pressed “Interact” always happens. So in this case, only character nr. 2 should be able to perform “Interact”.

Any help is appreciated :slight_smile:

Hi again!

Yes, in the level BP. Here is a screenshot:

Hello, Stradis!

In which BP are you possessing the other characters? Are you doing that on your level BP?

Yes, that is also in the level BP. Just in case it’s of any help, I’ll add screenshots of that as well so you can see how it gets executed:

I was afraid that might be the only solution, but that really makes things complicated for me since I have no idea how to successfully use casting and create references in character BPs. It would be really handy if the interact logic could remain in the level BP.

I assume there is no workaround for this?

And where are you executing you “Interact” logic? Are you doing that on your Level BP as well?

You should execute your “interact” logic on your Character BPs. That way you are only calling Interact for the character that you have possessed.

If you’re free around 530 central time, I can help you with this bit. You’re going to need to move some stuff around to get this to work the way you want.

If you don’t want to move this bit, there are a few other things you can do on your Level BP like setting up Booleans to make your Interact logic character specific.

Oh nevermind my previous comment then! Yes I think using Booleans might be a more suitable solution in this case.

I am free around that time. That would be in around 7 hours, correct? (I live in The Netherlands)

There is! I assume each character has different interaction logic they will execute? You can use a Enumeration system… Create a new Enum BP called Possessed Character. Create three options (one for every character that will be possessed). In your Level BP create a new variable that is that Enum BP. Now you want to set the enum variable after you Possession logic (keys 1, 2 and 3). Now you will want to “Switch on Enum” after you “Interact” key event.

This will work somewhat like a boolean… when interact is called, it will look at the enum and see which character is selected and then only execute that logic.

If you’re interested in getting it set up the way I suggested previously, let me know and I can help you get there!

Hope this helps!
Matt

Create a Boolean variable for Character 2, name it however you want ie: (isPossessingC2). Then connect it to all 3 Possess parts for each character in the player select part of your levelBP using “Get isPossessingC2”. Then

  • For input 1, the variable is set to False
  • For input 2, the variable is set to True
  • For input 3, the variable is set to False

Now create a Branch where your Interact stuff is at (Perhaps before the Character Range Branch) and the condition is that Boolean variable you created.

  • On True, connect it to what you are doing (the FlipFlop or whatever you are doing)
  • On False, do nothing (leave it alone)

Now, only when you press 2 and switch to character number 2, you are able to do the interact input action.

That did the trick. Thank you!

Hey! I tried the Enum BP approach, probably did something wrong because it didn’t work as I expected it to. But actually I found a solution through another user that worked for me, at least it works for what I’m creating. Although I realize my entire blueprint logic in this case might be a bit unorthodox :slight_smile:

Thanks a lot anyway, you always introduce me to new features in Unreal so that is great!

Since I cannot mark comments as accepted answers, for administrative purposes I will put this comment and mark thread as solved. For future answer-seekers, see comments below for the suggestions that have been given!

You’re most welcome!