How can I execute code immediately after loading a non-streaming level?
I'm working on Save/Load game code, and to load the level, I use GameplayStatics::LoadLevel(), and then set actor positions around the level to where they were saved at.
The problem is, LoadLevel() seems to only set some flags, and then the level is actually loaded on the next tick. There isn't any callback functions for when it actually is loaded.
I might be able to do this by using streaming levels, but there appears to be no way to open a level that wasn't already put into the persistent world by the editor. Plus, I'm using world composition as well, which may complicate that idea.
How can I get some code to run immediately after loading another level, without having to put a myriad of checks and flags in each level?
asked Mar 22 '16 at 05:11 AM in C++ Programming
My solution was to set a static flag, and since my game has only one game mode, I can override its GenericPlayerInitialization(AController* C) function to run my game load code after the level changes.
This is a terrible, terrible hack and still gets called before a pawn spawns from a "player start" placed in the level. Hopefully Epic can add a delegate somewhere that gets called after the level is fully loaded.
There are even a few of these delegates in code, but none are actually called, and are pretty misleading.
answered Apr 02 '16 at 09:00 PM
Old post, I know, but I've been working on this exact issue the last few days.
My solution was to create a custom ALevelScriptActor for any level I want to be saveable. Override BeginPlay, then after Super::BeginPlay(), put your loading code.
Still feels very hacky, but the player controller & pawn are spawned, would work across multiple game modes etc.
answered Jun 17 '16 at 02:21 PM
Resurrecting this post with another solution since Google brought me to this topic.
All you need to do is override GameInstance::LoadComplete(const float, const FString&). This one will get called reliably since GameInstance persists over level loads.
Personally I think this is a clean solution. Tested in UE4.22
Follow this question
Once you sign in you will be able to subscribe for any updates here