OnLevelUnloaded never firing event?

Greetings fellow developers. Something has been bugging my mind lately. It’s about LevelStreamingProcess.

To make a few things clear first, i have made a function like this :

void USparked_GameInstance::Level_Streaming(FName inUnloadLevelName, FName inLoadLevelName)
{
	UE_LOG(LogTemp, Warning, TEXT("Level to unload: %s , level to load: %s"), *inUnloadLevelName.ToString(), *inLoadLevelName.ToString());
	Level_Load(inLoadLevelName);
	Level_Unload(inUnloadLevelName);
}

As you can see, it’s a simple wrapper function to load/unload levels during runtime. It’s divided in 2 parts because i wan’t a progress bar to fill to 50% when it loads a level, and to fill to 100% when it unloads the previous level.
(During this process you see a loading screen).

Here is the unload function which gives me nightmares :

void USparked_GameInstance::Level_Unload(FName LevelName)
{
	if (LevelName != "")
	{
		UE_LOG(LogTemp, Warning, TEXT("Unloading: %s"), *LevelName.ToString());
		LevelToUnload = LevelName;
		FLatentActionInfo LatentInfo;
		UGameplayStatics::UnloadStreamLevel(this, LevelToUnload, LatentInfo, true);
		ULevelStreaming* Unload_LevelStreaming = nullptr;
		Unload_LevelStreaming = UGameplayStatics::GetStreamingLevel(this, LevelToUnload);
		Unload_LevelStreaming->OnLevel
		Unload_LevelStreaming->OnLevelUnloaded.AddDynamic(this, &USparked_GameInstance::Level_OnLevelUnloaded);
	}
}

And the reason for that is because it never fires “OnLevelUnloaded” on the last line. (Even though it’s the same for “load function” which uses “OnLevelLoaded” which works perfectly. and fires AddDynamic delegate.

What is the matter with “OnLevelUnloaded” never firing? The level it needs to unload is pretty simple, maybe 10 boxes in total… it’s just a main menu.

Thank you for your time, this is giving me a headache.

Funny thing is, that if i reverse function calling. For example:

  1. Level_Unload(inUnloadLevelName);
  2. Level_Load(inLoadLevelName);

Then unload delegate fires, but load delegate doesn’t fire? Maybe .AddDynamic can only be fired once or maybe it works in some mysterious ways?

The purpose of this comment is to give an additional clue to anyone willing to bother with this question of mine. I hope it helps.

Okay guys, this was driving me insane, but i have found a workaround until this “multiple .AddDynamic” delegates working in the same time is fixed.

I have just removed wrapper function, and now i have “Load_Level”, and “Unload_Level” separated. Both fire as expected.

PS: It’s a shame my wrapper function “Level_Streaming”.

Have fun developing, hope this helps someone!