0

I am new to UE4 game development, but I am try to achieve something simple, but not sure what the right method is.

I have multiple meshes in my level, each mesh is a different shape. I want to add an onClick event to each mesh that populates a variable indicating which shape was clicked.

The blueprint that handles the on click will be the same for each mesh. I know I can create a blueprint and add a mesh to it, but how can I create a "generic" blueprint and add it to any of my meshes? TIA for any suggestions.

Ruzihm
  • 19,749
  • 5
  • 36
  • 48
Ronny vdb
  • 2,324
  • 5
  • 32
  • 74
  • It's been a minute since I did anything in unreal so take this advice with a grain of salt. I believe you can extend `Actor Component` to create the blueprint. In this blueprint, you should be able to get the actor that it's attached to, and find the mesh from there. Then, you should be able to add a delegate/event to the OnClicked of that mesh, which gets the game mode and calls whatever function with whatever info you need from that mesh as an argument. then, this should work on any actor w/ a mesh you attach it to. – Ruzihm Jan 15 '20 at 18:19
  • You can also just collect all static mesh actors in the world and bind to their OnClicked event from a separate blueprint. – Rotem Jan 15 '20 at 23:11
  • @rotem thanks for your suggestion. can you elaborate on how to implement that? – Ronny vdb Jan 16 '20 at 07:02
  • @Ronnyvdb It seems my suggestion wouldn't be applicable for blueprints because you can't bind to an event in a loop. – Rotem Jan 16 '20 at 16:58

1 Answers1

0

I solved this problem by creating a Blueprint Actor Component that I could attach to each of my shapes (static meshes), and I handled the onClick event with the following nodes:

Example blueprint to handle onClick events  in Actor Component

Ronny vdb
  • 2,324
  • 5
  • 32
  • 74