Download

What am i doing wrong here

why does the main menu still open even tho I put an if statement to decide whether it should open or not what am I doing wrong here? also is it okay to open and close the menu from the character class or should I do it from somewhere else?

Instead of adding and removing the main menu, you should really just set the visibility on and off.

So you would check if it’s visibility is set to visible (or != hidden or collapsed), then if that’s true, hide it, if it’s not, show it.

that’s gonna be alot of work cuz there are so many other blueprints that remove or add the main menu to the screen and I have to change those as well. What’s the difference tho? that’s just another way of doing it. the is in viewport is just another way of checking it.

But you’re not even setting the reference for the MainMenu - we can’t see it in the image. It’s always false and it will always create a new widget.

Why would you do this? There’s no need to duplicate code. Have the other blueprint call the pertinent event in the Player Blueprint. The menu should be created in one place only and created only once as @Cd1232 suggested.

Then you simply show / hide it without wasting performance or losing data it was storing. A much simpler approach.

For example:

Now anything can call ToggleMenu.

True, presumably you promoted Mainmenu variable from create main menu widget before and now on escape you open new (duplicate) mainmenu widget.

yeah i did it the wrong way lol, I’m a beginner in game development tbh so I’m developing and learning at the same time. is there any quick fix for this or do i have to redo everything.

Included in the image. That’s literally all you need. Now those other blueprints should simply cast to the player and call this event. That’s it.

You’re better off doing it now. Because next time you want to update something, you will need to to go through all the duplicated code again, and again.

This IS the quick fix. :slight_smile:

1 Like

thanks. wish i knew this at the beginning.

So, the target in toggle menu would be the your player variable from level blueprint?
I think only level and character blueprints checks for keyboard input.
If you create mainmenu reference in character blueprint, than you don’t need to call toggle menu from other blueprints. Not sure if set game paused pauses the character input also.

one other problem that i encounter is when another menu inside main menu is open and the player presses the esc key it opens the manu on top of the other menu how do i solve that without duplicate code?

one other problem that i encounter is when another menu inside main menu is open and the player presses the esc key it opens the manu on top of the other menu how do i solve that without duplicate code?

When you Add to Viewport, you get to choose Z order:

image

The higher the value, the more on top things are - they’re drawn last.

All blueprints can process input, including widgets. Regular actor have it disabled by default, though. Here’s the order of input consumption: