Download

Widget doesnt disappear

Hey guys,

My problem is that my widget doesnt disappear and I dont know why. The button should open the level and then the wigdet should disappear but nothing happens… Under the World Outliner the map changed to the map which should be opened and all other stuff in it changed to but the widget isnt disappering. Here some screen I hope you can help me…

Worldsettings.PNG
MainHud.PNG
Button.PNG

Button 169 is just for testing, it is working…

Edit:

I am not in the same map when I try to open the map

Call the remove from parent node first then open level.

I did but its the same. Under Worldoutliner the map changed but the widget doesnt disappear.

Its working but since the level loads it fires event begin play which recreates the widget again

If this is wrong, try with a Delay node:

OnClicked Button > Remove from Parent > Delay > Open Level

Delay Duration can be 0.1s

Didnt work. Because I think ptjackson is right. Even though the level opened and I see my character, it doesnt last long. Because EventBeginplay the widget is appearing again and again. I managed it by putting all the nodes in the level blueprint. Thanks for your help!

Next problem xD:

Problem.PNG

Should it not add the UI Widget. I try it with a custom event but didnt work so I thought something is wrong then I try it like this and it is still not working…

It is working when I create the widget in the levelblueprint and add Eventbeginplay but I want to know why both of them aren’t working like they should… or did I something wrong (probably it is my fault). Have you guys a solution for both problems?

The first version, the original one, fails because of this:

You have a GameMode. In this GameMode you have a HUD Class defined. In that HUD Class, you are spawning the Widget on BeginPlay.
In the Widget, you open the Level, probably with the same GameMode, aka the same HUD Class. So as soon as you switch the Level, it calls BeginPlay on the
HUD and opens it again.

The BeginPlay version of the LevelBlueprint is the same, as long as you open the same Level.
If you want to stop this, you have a few things you can do:

  • Have a different Level that uses a different GameMode

  • Open the existing level with the option “?game=GameModeShortcut”, which opens the Level and uses the defined GameMode

That means you need a different GameMode that does not use the HUD Class, similar to above. You can add GameModeShortcuts in the Map and Modes section of the Project Settings in 4.14.
Pre 4.14 needs to add these things in the DefaultGame.ini

  • Use the GameInstance to create the Widget

The GameInstance only gets added ONCE when you start the Game. It only gets destroyed if you stop playing. Changing the level doesn’t affect the GameInstance (despite destroying current Widgets while the world gets deconstructed).
You can create a GameInstance similar to all other Blueprints and set what GameInstance should be used in the Maps and Nodes options of your ProjectSettings (at the bottom).

The “BeginPlay” function of the GameInstance is actually called “Init”, so search for that.

I hope that answers your question.

Yes, this answered my question! I think I understand it now. Thank you!