x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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!

Product Version: UE 4.12
Tags:
more ▼

asked Nov 02 '16 at 09:53 PM in Blueprint Scripting

avatar image

CorbisHETB
30 5 6 9

avatar image KenBrace Nov 03 '16 at 11:23 AM

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.

avatar image CorbisHETB Nov 03 '16 at 05:32 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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.

more ▼

answered Nov 14 '18 at 09:20 PM

avatar image

CorbisHETB
30 5 6 9

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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!

more ▼

answered Nov 04 '16 at 02:48 PM

avatar image

Derzo
691 28 8 50

avatar image CorbisHETB Nov 06 '16 at 02:32 PM

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:

alt text

alt text

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!

ue4button1.png (205.5 kB)
ue4button2.png (116.3 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question