Best Practices for Passing Button On Click Event to Player Pawn (Event Dispatcher or Object Reference?)

Hi all!

I am making a small management-style game where you place buildings. I want a menu to initiate the ability to place buildings, so I want to pass a button click event from my HUD (which I created and overrode in my Game Mode) to the Player Pawn.

I was able to pass an event by binding an event dispatcher but it feels like a lot of heavy lifting for communication between just two blueprints (I don’t think I will need more than one blueprint to listen for this click event).

Here is my work-in-progress, does anyone have any suggestions for a better setup?

Is it better to just have an object reference to the button itself instead of an event dispatcher? I am hesitant to do so much work on Begin Play. Would I have to do this for every button?

Thanks for any help!

I’d go with interface calls instead.

Then your UI can always stay the same, and whatver you implement on whatever receives the message/implements the interface can change at will.

1 Like

Like this here my friend? Blueprint Interface in Unreal Engine | Unreal Engine 5.3 Documentation

I suppose here is a different way to phrase the question: design-wise, does it make sense to directly communicate between the player pawn blueprint and the HUD? Any issue with the HUD holding a reference to the player controller or player pawn?

Well yes, references can break.

Does it matter? Probably not. Just make a function that seeks out the correct pawn and if your reference ever fails to validate you just run the function again…

1 Like

Thanks!

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