The most efficient way to create a pushable button
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.
asked Nov 02 '16 at 09:53 PM in Blueprint Scripting
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.
answered Nov 14 '18 at 09:20 PM
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.
Follow this question
Once you sign in you will be able to subscribe for any updates here