Call Level Begin Play in C++

Hello,

I have levels like: Login, Loading and MainMenu, I created Widgets for them which contains graphics like background image and so on, they are called WBP_Login, WBP_Loading and WBP_MainMenu.

I wonder how I can set these Widgets to UI when player enters some of these levels in C++, because there is nothing like Level C++ Class afaik which contains Begin Play for specific level.

Thank you

Single player or multiplayer?

If you’re using single player and not using level instances, you can use a custom GameInstance. You can then override LoadComplete. It’ll pass in the name of the level that was just loaded. Since you just want to display UI, it may be ok to display them before the level instances are loaded if you have those.

There’s also OnWorldChanged which will give you the UWorld for the new level, but it won’t be loaded yet. You have to wait for LoadComplete first. But if you want the UWorld, that’s an easy way to get a reference to the new level.

Unfortunately, you can’t use GameInstance in multiplayer as that only exists on the server. And I haven’t done much with multiplayer yet, so I can’t help you there.

Level blueprints use ALevelScriptActor as a parent class, so you could conceivably make your own that inherits from that and then override the base in the specific level where you want to use it.