How do you make a widget appear when entering a collision box?

Hello, I have already created my widget that I want to appear and have placed a trigger box where I want the widget to be displayed but I don’t know how to code it properly. Any help would be great :slight_smile:

Hey there Shannon. Triggering a widget’s visibility can be done by using bindings in the widget’s “designer” area. But there’s a bit of setup that needs to happen first. [I made a step by step video showing how I did it.][1]

  1. Make a widget (I believe you’ve done this) - Right Click on the Content Browser, then > User Interface > Widget

  2. Call the Widget in the level - Go to your level blueprint and on EventBeginPlay do this:
    (My widget is called Widget to Show)

  1. Make a boolean variable inside your player character (or whichever actor you use to trigger the box) and set its default to false.

  2. Drop a trigger box, click on Blueprint/Add Script button to make it a blueprint. On its event graph, do this where WidgetVisible is just a boolean I created and CastToTopDownCharacter should be replaced by whichever actor you want to trigger the box:

  1. On the Widget’s design panel, click on the object you want to hide and reveal, and on its properties, go to Behavior, set its visibility to hidden, then click on the Bind dropdown and create a new Binding. That should look like this:

137349-screen+shot+2017-05-09+at+2.00.40+pm.png

Then open the newly created bind function (probably called GetVisibility_0) and add this code:
(I created the WidgetVisibility variable by right clicking the return node’s result value and choosing promote to variable)

Then it should all work. Good luck!

Thankyou so much for your response. This has worked perfectly :slight_smile:

Just another quick question. I am wanting to put two widgets on in different places but when I try to get this working the text overlaps each other. Do you know how I would separate this? Below is the blueprint and I want the top two boxes to be added in somewhere but nothing seems to work for me.

Hmmm… Let me see if I understand what you’re asking.

You want to add two widgets, each in a specific part of the screen. But they are ending up one on top of the other. As far as the nodes in the picture, you should just be able to plug them in right after you add the first widget to the viewport at the end of Then1 (I don’t really know what you’re doing with Then0). They’ll overlap only if you’ve placed them in the same coordinates in their respective widget designer view.

Go to each widget’s designer view (doubleClick them in the content browser) and drag them to opposite sides of the canvas and see if they still overlap.

Ok. That said:

My question is, do you really need more than one widget? You can have more than one object on a widget and change the visibility individually.

For instance, these two buttons (The ones on my pictures) are being triggered independently by different trigger boxes, but they live inside the same widget. Having them in the same widget makes it easier to place them in relation to each other and make sure they don’t overlap.

137369-screen+shot+2017-05-09+at+4.41.10+pm.png

Other than that, if you have to use several widgets, then you can still manually position each object on the canvas panel in their designer area so that they avoid each other. You will just have to do it without the other widget as a visual reference.

Hopefully this helps.

Hello sorry for the late reply but the problem is that I have two collision boxes in which I want them to say different things when you walk up to them but when I try to code them together the text overlaps. I’ve attached some photos so you can see what is happening.

Hey there. I modified the code so that you can use more than one bit of text. Unfortunately, since this question has already been marked as answered, it won’t let me post pictures of the code. So I’m sending you a dropbox link to my project and a bunch of pics of the relevant code.

The project has a bunch other stuff that is not what you’re looking for, but there are two trigger boxes on the stage that should be helpful.

Thankyou for your reply, but unfortunately it won’t let me open your project for some reason, I’ve tried to convert it to the correct engine number I have but it still won’t let me open it.

how to make the same concept in c++?i need a idea to create a button in c++ and create the function to change the material? please help me