[4.6.1] UMG not responding after opening a new level

I create a UI at the beginning of the game, and I open another level, the UI still remain but it does not responding anymore(can’t click), I’m not sure if this is a bug, how do I fix this?

By the way, is there a place where the code will just be executed once? I noticed if the “Event Begin Play” in the GameMode will be called again if you open a level, I want my UI just to be created once. Right now I create my UI in a level blueprint, which is not a good place obviously, if the level opens second time then my UI will be created twice.

Thank you.

I think the levelblueprint is the right place. So keep it there. But if you reopen the same level, you should remove the UI before … so the open will load it again.

Hi Dredok,
Thanks for replying. I understand I can destroy the UI, but there’s a chance that I will reopen this level many times, is it a good way to frequently create and destroy the UI?

Yes, I guess so. Creating and destroying the UI once per level loading does not sound like something prohibitive to me. The level loading itself must be way more expensive than creating / destroying the UI.

If you absolutely want to limit the creation/destruction of UI to a single time, you could handle it by using a custom GameInstance. For example on level loading BeginPlay you could test if the UI is created asking GameInstance (which only exists one instance in the game). If the UI does not exists, then create it. BTW I think this is unneeded and I would stick to creation/destruction in level script.

You are correct that your level blueprint is not the right place for that, neither is the game mode unless the game is a single player one. Create the UMG widgets, and then instantiate them on the player character. Since the player character will, obviously, be moving from level to level, they should work just fine there.

Frankly, creating the ui is trivial in terms of CPU time. If you want to minimize that, on the characters On Event Begin Play event, create the widget and add it to the view port. It will only be created once per level, and as I said, it is trivial in terms of overhead. About the only time that you don’t want the UI elements on the character is when the character is not loaded, such as at the start game screen.

Thank you Dredok, I will look into the GameInstance.

Hello,

I wanted to jump in here and answer the original question as to why your widget was no longer responding to you. This would be because you had two instances of the widget added to the screen. When this happens the older widget loses reference and only the newest instance of the widget will respond to the user. You will no longer be able to remove the old widget from viewport/parent. So whenever you add a widget to the viewport beyond the first time without first removing it, they will continue to stack up. I hope this answers your question.

Make it a great day

Hi ,

Thanks for replying. I have two levels, and the UI is created in the level blueprint of the first level, I tested loading the first level, and then open the second level, I think the UI widget is created once in this way(maybe I was wrong), but when in the second level, the UI stopped responding.

Hello,

The widget in that case is not getting added to the screen an extra time, however it will result in the same effect. You will need to remove your widgets before switching levels. If you would like that same widget to be used on the next level; simply add it back in on begin play.

Make it a great day