The most efficient way to create a pushable button

Hi!

I’ve been working with blueprints for a little while now, but I still have problems when it comes to different blueprints communicating.

What I want is a button that the player can push and activate when they are within a certain range, and looking at the button. There are loads of tutorials when it comes to buttons, but for some reason, most of these tutorials only use hitboxes, but no actual interaction.

The button should be duplicateable, I should be able to create a blueprint I can simply drag into the level, and have it working. It doesn’t matter what the button is activating, it is only meant to give a simple bool pulse to true, nothing else.

My idea is that the character blueprint, button blueprint, and whatever is supposed to be activated is connected together in the level blueprint. I would add a referance to the player, connect it to a reference to the button, and connect that further to the thing that can be activated.

How do I go on about this? In what way can I make it efficient to place sever buttons into the level, and several objects that can be activated? How do I make the player and button communicate? How can I tell the engine what button is pressed by the player? If all of the buttons give off one signal, the entire point of several buttons is gone.

I know this might seem as a really easy question, and it probably is, but somehow I haven’t found a proper way to do this that supports several of the same objects, easy to edit and add to in the level blueprint.

It would also be great if you havea method of making it mulitplayer compatible, but if it means that I have to change evrything, it doesn’t really matter for now. If you have any questions on what the game is supposed to be like, just ask, I’m happy to give as much information as possible to get this right.

Thanks!

So you want an actual button inside of the game? Do you want the cursor to be shown as soon as the player is within range so that the button can be clicked? I don’t completely understand the setup you are trying to create.

Exactly, a button object I can place in the game, the button can be higlighted, or not, I will have a cursor in the middle of the screen anyway, so it isn’t that important, but just the main function of it.

Hey!

It has to be an actor blueprint, I’ll call it BP_button. Add a sphere collision to it and a button static mesh. Set the sphere collisions collision to ignore everything else, but block visibility channel.

Create an enum called ButtonActions, add the things you would want to do with the button and add it as an variable to the BP_button. Make it public so that you can edit it in level viewport.

In your character blueprint on tick, line trace forward, cast to BP_button from the hit result actor and if the cast was successful, promote it to a variable. If failed, set that variable to none.

In level blueprint, add a button event, such as left mouse button. When it’s pressed, you cast to character blueprint, check if BP_button variable IsValid and if is, get its ButtonActions enum, add a switch on enum and there, done!

now you can easily drag multiple copies of BP_button in the level, set their action type and create scripts in level blueprint for the different actions.

Cheers!

Okay, I tried to do what you said, and connected the enum switch to a toggle visibility on a point light, but the hit result turns positive no matter what object it hits, and I can toggle the light without even having a hit result, just pressing the right button toggles the light anyway. Here is the blueprints for the character and the level blueprint:

I know that there is something wrong here, at least with how the hit result is set, but I don’t know how it should be done. Thanks for the help btw!

After a long time, I’ve finally figured out a system that’s modular enough. It’s a bit messy, but leave a reply here if you would like to know how.