why i need to press twice to close

I want to implement a feature where, when standing within a box collision volume and pressing E, a widget opens to display a mini-game interface, and pressing E again closes it. Right now, after I create the widget and set the UI Input Mode Only, theoretically pressing E again should close the UI instead of creating another one. Could anyone help me figure out where the problem is?

(post deleted by author)

how can i share the link of this blueprint?i paste the Code to Embed,but it doesn’t display

just like this

Hello @namehardhard ,
What I would suggest is starting by creating a Blueprint Interface called BPI_Interactable_MiniGame. Inside it, you can define two functions: OnInteract and IsInteractable, where IsInteractable should return a boolean so you can control when an object can actually be interacted with.

After that, create your interactable blueprint ,for example BP_TriggerMinigame and add the interface in the Class Settings. In that same blueprint, make sure that IsInteractable returns true so it can be detected by the player.

Then you’ll need to create an Input Action ,IA_Minigame and assign it in your IMC_Default to whatever key you prefer ,in this example , I used X.

Once that’s set up, go into your BP_ThirdPersonCharacter and handle the input by doing a trace from the camera. With that trace, you can check if the hit actor implements your interface and whether IsInteractable returns true. If it does, you simply call OnInteract on that actor.

From there, you can implement the interaction using two different approaches.
In one approach, you create two custom events: one that creates the minigame widget and disables player look input and movement, and another that removes the widget and restores control. You store the widget reference by promoting the return value of Create Widget to a variable (for example MiniGameHUD), and in OnInteract you add a Branch that checks whether the widget is already open ; if it’s true, you close the widget, and if it’s false, you create and display it

In the other approach, you create the widget directly inside OnInteract, store the reference, and set the input mode to UI Only while passing the widget as the focus.


Then, inside the widget, you handle the input using OnKeyDown

Making sure the widget is focusable and the canvas is set to visible so it doesn’t lose focus, and so that if you click on an empty area of it you can close it again


Both approaches work correctly, so it just comes down to which one fits better in your setup.

Hope it helps!

To take nothing away from the answer provided by @BRGEzedeRocco, I just wanted to zero in on two possible issues:

Your screenshot doesn’t make it clear that you have a connection between ‘In Key Event’ and ‘Equal Equal Key Key’, and you need to return ‘Handled’ at the end of your ‘On Key Down’.