Hi, I’ve some problems for level streaming in C++. I want to load a stream level, unload existing one after previous one has loaded. I’m working on this for 2-3 days and I didn’t figure out how to do it.
My first question is about delegates. OnLevelUnloaded delegate is not working when I trigger UnloadStreamLevel from GameplayStatics. It triggers OnLevelHidden (?)
Secondly, in first use, (Load->Unload) it’s working. When I want to unload currently loaded level and load hidden level, it’s not working. When I’ve looked the code, it’s searching for ExistingActions. If there’s one, loading or unloading doesn’t happen. But when I remove actions for the object, it doesn’t trigger like I didn’t remove them.
void AAndroidTpsGameMode::LoadLevel(const FName& InLoad, const FName& InUnload)
{
UnloadName = InUnload;
ULevelStreaming* Streaming = UGameplayStatics::GetStreamingLevel(this, InLoad);
if(Streaming)
{
Streaming->OnLevelLoaded.Clear();
Streaming->OnLevelLoaded.AddDynamic(this, &AAndroidTpsGameMode::OnLevelLoaded);
FLatentActionInfo Latent;
Latent.CallbackTarget = this;
Latent.UUID = 1;
UGameplayStatics::LoadStreamLevel(this, InLoad, true, false, Latent);
}
}
void AAndroidTpsGameMode::OnLevelLoaded()
{
print(-1, 5.f, "Level Loaded!");
FLatentActionManager& LatentManager = GetWorld()->GetLatentActionManager();
if (LatentManager.FindExistingAction<FStreamLevelAction>(this, 1) != nullptr)
{
printf(-1, 15.f, "LatentDescription: %s", *LatentManager.GetDescription(this, 1));
LatentManager.RemoveActionsForObject(this);
LatentManager.ProcessLatentActions(this, GetWorld()->GetDeltaSeconds());
}
ULevelStreaming* Streaming = UGameplayStatics::GetStreamingLevel(this, UnloadName);
if (Streaming)
{
Streaming->OnLevelHidden.Clear();
Streaming->OnLevelHidden.AddDynamic(this, &AAndroidTpsGameMode::OnLevelUnloaded);
FLatentActionInfo Latent;
Latent.CallbackTarget = this;
Latent.UUID = 1;
UGameplayStatics::UnloadStreamLevel(this, UnloadName, Latent, false);
}
}
void AAndroidTpsGameMode::OnLevelUnloaded()
{
print(-1, 5.f, "Level Hidden!");
FLatentActionManager& LatentManager = GetWorld()->GetLatentActionManager();
if (LatentManager.FindExistingAction<FStreamLevelAction>(this, 1) != nullptr)
{
printf(-1, 15.f, "LatentDescription: %s", *LatentManager.GetDescription(this, 1));
LatentManager.RemoveActionsForObject(this);
LatentManager.ProcessLatentActions(this, GetWorld()->GetDeltaSeconds());
}
}
It works perfectly on Blueprints but I want to understand why C++ version is not working. Thanks in advance…