Skip to content

Instantly share code, notes, and snippets.

@ivo-alves
Last active July 5, 2023 09:31
Show Gist options
  • Save ivo-alves/07a29a255600fc55ef2413ee7b20039a to your computer and use it in GitHub Desktop.
Save ivo-alves/07a29a255600fc55ef2413ee7b20039a to your computer and use it in GitHub Desktop.
// non static
FDelegateHandle handle = FWorldDelegates::OnCurrentLevelChanged.AddUObject(this, &Foo::OnLevelLoaded);
// static
FWorldDelegates::FWorldInitializationEvent::FDelegate Foo::OnPostWorldInitHandle = nullptr;
Foo::Bar()
{
if (!OnPostWorldInitHandle.IsBound())
{
OnPostWorldInitHandle = FWorldDelegates::FWorldInitializationEvent::FDelegate::CreateStatic(&Foo::OnWorldInit);
FWorldDelegates::OnPostWorldInitialization.Add(OnPostWorldInitHandle);
}
}
void Foo::OnWorldInit(UWorld* World, const UWorld::InitializationValues IVS)
{
GEngine->AddOnScreenDebugMessage(-1, 5.5f, FColor::Blue, TEXT("OnWorldInit!"));
FLatentActionInfo Info;
UGameplayStatics::LoadStreamLevelBySoftObjectPtr(World, LoadingDrill->DrillSublevel, true, false, Info);
}
// non-static
UFUNCTION()
void OnLevelLoaded(ULevel* NewLevel, ULevel* OldLevel, UWorld* World);
// static
static void OnWorldInit(UWorld* World, const UWorld::InitializationValues IVS);
static FWorldDelegates::FWorldInitializationEvent::FDelegate OnPostWorldInitHandle;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment