Loading level without recreating HUD

Hello,

How is it possible to load new 3D level without recreating HUD, GameMode e.t.c.

Currently when I do, GetWorld()->ServerTravel(…)
all my customization flies away.

And question related to above, can you hint me a place in C++ code where I can put my init/deinit code and which will be guaranteed to be called once at game startup and shutdown. I keep global variable as a last resort, I would love to avoid it.

Thank you.

Use the GameInstance for data to be used between levels.

I don’t have a good context on what you’re trying to achieve. But from what you said maybe you could use level streaming?

The Level Streaming feature makes it possible to load and unload map files into memory as well as toggle their visibility all during play. This makes it possible to have worlds broken up into smaller chunks so that only the relevant parts of the world are taking up resources and being rendered at any point. If done properly, this allows for the creation of very large, seamless levels that can make the player feel as if they are playing within a world that dwarfs them in size.

Okay, second part of the question is sorted, thanks for that! Though it didn’t really help me.

I do have to find a way to load maps without recreating AHUD / Viewport classes. My game dynamically creates Hud stuff, and 3D scene is just a background I want to replace at runtime.

Thanks Bino,

Glad to see someone (finally!) crashes questions community have! :slight_smile:

Okay, I googled a bit on Level Streaming and it looks promising indeed, though now I need to close the gap between code and Unreal Editor.

I will explain what I have so far:

  1. I created level. It’s reference path: World’/Game/3D/Maps/LoginScreen/LoginBackground.LoginBackground’

  2. At UE4.11, Window / Level - I drag and dropped my level into the window. Now I see LoginBackground entry, under “Persistent Level” group, with blue circle on it’s left.

  3. I saved and cooked resources (just in case)

  4. Now in code (once game is loaded), I say:
    FLatentActionInfo info;
    UGameplayStatics::LoadStreamLevel( GetWorld(), L"/Game/3D/Maps/LoginScreen/LoginBackground", true, true, info);

  5. In output LOG I see this line:
    LogLevel:Warning: Failed to find streaming level object associated with ‘/Game/3
    D/Maps/LoginScreen/LoginBackground’

Do I incorrectly provide path, or how do I create streaming level object? Youtube tutorial didn’t show anything more that registering them as a part of “Levels” window.

Actually you know what, I found the answer

Whoo-hoo!

Whoo! high five :slight_smile:
All the best with your game!