Best way to set up context menus for different game objects on right clicking them?

Hey guys. In my game, I’m trying to make it so that if I right click any object in the game, it’ll bring up a menu of options for that particular object. For example, if I right click on a tree, a menu option to “chop” it will come up and if I right-click a rock, a ‘Mine’ option will come up. My question is what’s the best way to do this in UE5?

So far, I know I can either put different interfaces on every different object and do a “does implement interface” check or have all objects as different classes and check for each class and bring up the menu based on the class. Both of these options don’t seem ideal because I’ll have to do checks on the right-clicked actor for every possible interactable in-game object.

Any way around this? I would greatly appreciate some help. Thanks.

1 Like

How I would approach it is to have a component create and populate the widget. On right click check if the actor undor cursor has the component. The base class of the component would be refenced directly so no interface is needed.

Like this any actor with the component can have a right click functionality.

1 Like

In UE5, a streamlined approach for your context menu would be to use a component-based system. Attach a component to your interactable objects that defines the options available upon right-clicking. This way, you can check if the actor under the cursor has this component and populate the menu accordingly, without needing multiple checks for different object types.

2 Likes

Thank you so much for your replies. I’ll try to follow what you all suggested.