Assign mouse buttons/keys different actions based on which item/"state" is equipped?

Hi all! Fairly new to UE4, usually just model stuff but I thought I would tackle making some games for once. Am currently working through a bunch of UE4 tutorials while slowly implementing what I’ve learned into my project, learning my way around Blueprints, and so far it’s been an enjoyable challenge (more intuitive than Unity imo). I’ve searched far and wide, but so far haven’t had any luck finding a solution to this particular question. I’m pretty sure I’m not grasping something because this seems pretty basic.

The goal is to have my character be able to equip an item; this item has several different “states,” and based on the state, I want the mouse buttons and other keys to execute different actions. So, one state allows the character to click to pick up and (release) to hurl objects. Another allows you to click to defend/counter or attack, another creates a fire spell, etc. I want to set it up so the player can scroll through and select a “state,” and then the mouse/key functions change accordingly. There would also be a non-equipped state, where clicking allows you to simply examine an object.

Is this fairly simple to accomplish? What obvious thing am I missing? So far I’ve only found ways to map a key to a single event/action, and I feel like a dolt because I’m not sure how to even search for more information on this. So if anyone understands what I’m asking and could point me in the right direction or provide a tut I would be immensely grateful!

Thanks!

In the Content Browser create a new Struct and add all the states to it. In the Blueprint, create a new Variable and make it Enum(name_of_struct). After your buttonpress event, add a SwitchOnEnum node and drag the pin of your previously created Variable into it.
I’m not on my machine right now, I’ll provide screenshots once I’m home if needed.

Don’t forget that while you can handle the functionality of the mouse clicks and selections in the player controller, the actual coding of what to do with the object is probably best left to the objects themselves. Like in real life, there are many ways to get to the end result of where you are trying to get to. For example, the Use command:

For example, in the player controller you can have that enum state set to Use and broadcast that to the object blueprint. The object would then interpret the use of itself depending on what it is. I’m not sure how your game would react, but in my case food is used differently than chairs which is used differently than Angela.

I would have the parent blueprint called food_master be in control, making the Use message translate to eating the food for some effect or something. Then the food would disappear because it was used, or eaten. I could also make it so the food would be thrown if used, or placed into a vehicle’s tailpipe (like bananas for instance, pretty popular gag in Beverly Hills).

My chairs would allow the player to sit on them or placed into a reclined position if used. Angela, the sweetheart that she is, would probably look at you differently once she felt used by you. I would likely not want to eat the chair or Angela nor would I want to sit on the food or hurt the chair’s feelings, unless those were indeed options that I could give the player. Could happen, it’s a game. It’s your world, do what you want. I’m not here to judge.

The point is, you can switch on Enum and provide differing functionalities to the different items / states that are available, but the decision of how to interpret the states is coding best left to the items, otherwise your controller becomes much more complicated. Using the Parent / Child relationship of blueprints is fundamental to this type of system.

I would combine this system with an Interface. That way you can have a ‘Use’ function implemented across Food, Chair, and Agela.