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…
Didnt work. Because I think 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!
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.