How to add onBeginCursorOver to all components of an Actor (Blueprint) ?

I’m working on a point&click puzzle game. This means the game has many Actors that can be interacted with (mouse over, mouse out, left mouse button click). Each Actor has a variable number of components (collision shapes or static mesh). The player interacts with an Actor at the level of the component.

If I have to set this up manually for every actor in the game, it will be a huge job. For instance, a box that needs to be unlocked with a key before it opens and the content inside the box can be picked up. For the keyhole alone, I would need to set up 3 events (mouse over/out, click).
I would like to set up the 2 mouse events for all components in onBeginPlay, since they are the same for all components. However, I can’t figure out how to do it.
I can get an array of sceneComponents for the Actor … but then what ? How do I tell each one of them to respond to eg. onCursorOver ?

Can anybody point me in the right direction ? Thanks !

1 Like

This is where blueprint inheritance comes in handy… :slight_smile:

You can make a master blueprint, which contains the code for whether components are interactable or not, and what can happen with them etc.

Then all the other blueprints inherit from this master

Thanks @ClockworkOcean ! That is exactly what I’m trying to set up : a generic interactable actor that can be inherited from. The problem I’m having specifically is that events (such as cursor over) are tied to 1 or several components of the actor ; not to the actor itself.
Would you have any idea on how to set that up ?

I will come back a bit later, not at a machine rn… :slight_smile:

1 Like

Make an empty actor blueprint, and put this code in it

Then, you can create a child from this

image

Put some meshes in it, and, voila :slight_smile:

interact

If you want to try this behavior on one of your other blueprints, just reparent it

2 Likes

Thanks ! I will read your explanation more carefully tomorrow morning & try it out. I’m too tired to think now :slightly_smiling_face:

1 Like

I was looking at a bottom up approach using SceneComponent BPs, but your approach works perfectly. Thank you !

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.