How to set up key input for an event?

Hey all,

I am trying to set up logic for making a character (the Carrier) carry another character (the Child). I made a visualization of what I am trying to achieve:

And here is the Child blueprint for my logic.

As you can see, the blueprint yet has to include the key input. So far, the Carrier (that is BM_Character) will automatically pickup the Child (KH_character) upon collision, i.e. by simply walking up to it.

I have already created an input for Action Mapping in the Project Settings, now I simply need to know how to implement it. Ideally, I want the Carrier to use the key input for carrying the Child and also for dropping it off.

BUT… there is something that might make this a bit complicated… My game consists of three characters who all use the same Axis Mappings, but use different blueprints. A single player assumes control over these characters by switching possesion. It is very important that the key input for the carrying/dropping is only possible when the Carrier character is possesed by the player. See level blueprint:

Also I’m not sure if utilizing the Child blueprint is a smart way of going about this (since the Action Mapping should be assigned to the Carrier), so if this is a dumb idea please tell me so.

Hopefully someone can help me out a bit :slight_smile:
Thanks y’all!

What I would do is take a line trace by channel from the camera in front of the camera a distance each frame then check if its the proper class, then set a bool like isLookingAtTheChild = true, and then have the input key event check whether the child is in sight based on that bool then if it is then attach the child to whatever socket you have set up or child actor or whatever! Hope this helps!

Hello again Stradis!

On your Child BP (was key?) you are going to want to add and “On End Overlap” and cast to your character. Create a boolean called something like “InRange” and set it to true when you Begin Overlap, and to false when you End Overlap. In the Event Begin Play on your Child BP you’ll want to cast to your character and promote it to a variable.

On your Character BP you are going to first make another boolean called something like “ChildAttached”. Next you need to set up an Event Dispatcher called something like “PickupChild”. Then use your InputAction M key and do a branch to see if ChildAttached is true. If it is true, you don’t want to add another Child BP if you have multiple in your level. If it is false you want to drag from your “PickupChild” Event Dispatcher and use the “Call” option.

Back to you Child BP you can drag from the promoted character variable and say Bind Event to PickupChild. That will give you a node that has a red box. Drag from the red box and add custom event. From that custom event you will need to first check to see if “InRange” is true, and if it is, attach the mesh as before and then set “ChildAttached” to true from the Character Reference we got when we used “Event Begin Play”.

Hope this was helpful!

Matt

Hello again! I set up some things, but I don’t think I quite follow what I have to do, since I’m not familiar with some of the nodes and how they should be used. I’m pretty sure I made a huge mess out of the blueprints, haha :smiley:

Carrier BP:

Child BP:

Also I’m unable to bind events, but I’m pretty sure that’s because I did something wrong earlier.

Oh nevermind, I found out some things. But I’m pretty sure it’s still not correct.

Hey, thanks for your reply. I’m sorry but I’m a complete noob when it comes to blueprints, so I’m afraid I don’t completely follow… I need some visual aid :wink: Do you know a tutorial/video where this is demonstrated or if it’s not too much of a hassle, maybe make a screenshot yourself?

After several attempts, I figured it out by myself! For those who might be wondering and have run into the same issue as me, here is my blueprint:

It might be a bit unorthodox, but it’s working so why not :wink: