Editor hangs in "Unloading level" when binding custom delegate in level instance blueprint

Hi!

I am working on an open world level with world partition which in turn means I can’t reference triggers or other actors in the main level blueprint without marking them all as non-spatially loaded. To avoid having to do that, I create a bunch of level instances for all those triggers.

The problem arises when I try to bind a delegate from my project code in the level instance blueprint. For example, I have a OnInteractionComplete delegate that’s defined with DECLARE_DYNAMIC_MULTICAST_DELEGATE as a public UPROPERTY(BlueprintAssignable, Category = Interaction) in my interaction trigger actor. When I add that event to the level blueprint and then exit the level instance edit mode, the editor hangs freezes in “unloading level” (without an actual crash). When I force quit the editor and open that level, it freezes as well, again without actually crashing.

I can use all other kind of delegates in Unreal classes (overlap events, MovementModeChanged in Character,…) even if they are declared exactly as my delegates, but it seems that all my custom delegates cause this error.

Unfortunately the log doesn’t output anything useful, except maybe that last line?

Log          LogSlate                  Window '[[Level Instance Name]]' being destroyed
Log          LogWorld                  UWorld::CleanupWorld for World_14, bSessionEnded=true, bCleanupResources=true
Log          LogSlate                  InvalidateAllWidgets triggered.  All widgets were invalidated
Log          LogWorld                  UWorld::CleanupWorld for [[Level Instance Name]], bSessionEnded=true, bCleanupResources=true
Log          LogSlate                  InvalidateAllWidgets triggered.  All widgets were invalidated
Log          LogWorldPartition         UWorldPartition::Uninitialize : World = /Game/Maps/[[Path]]
Log          LogUObjectHash            Compacting FUObjectHashTables data took   1.70ms
Log          LogUObjectHash            Compacting FUObjectHashTables data took   1.61ms
Log          LogUObjectHash            Compacting FUObjectHashTables data took   1.46ms
Display      LogStreaming              ULevelStreaming::RequestLevel(/Temp/Game/Maps/[[Level Instance Name]]_LevelInstance_58b1a4fc68cdbfa5_0) is flushing async loading
Display      LogStreaming              FlushAsyncLoading(): 1 QueuedPackages, 0 AsyncPackages
Log          LogWorldPartition         ULevel::OnLevelLoaded([[Level Instance Name]])(bIsOwningWorldGameWorld=0, bIsOwningWorldPartitioned=1, InitializeForMainWorld=0, InitializeForEditor=1, InitializeForGame=0)
Display      LogWorldPartition         WorldPartition initialize started...
Log          LogWorldPartition         UWorldPartition::Initialize : World = /Temp/Game/Maps/[[Level Instance Name]]_LevelInstance_58b1a4fc68cdbfa5_0.[[Level Instance Name]], World Type = Editor, IsMainWorldPartition = 0, Location = V(X=-41827.11, Y=131337.37, Z=2344.58), Rotation = R(0), IsEditor = 1, IsGame = 0, IsPIEWorldTravel = 0, IsCooking = 0
Log          LogActorComponent         ReregisterComponent: (/Temp/Game/Maps/[[Level Instance Name]]_LevelInstance_58b1a4fc68cdbfa5_0.[[Level Instance Name]]:PersistentLevel.Brush_0.BrushComponent0) Not currently registered. Aborting.

Does anyone have an idea how to fix or work around this?

Thanks!

Could you try BindWeakLambda

Static: Binds a weak object C++ lambda delegate technically this works for any functor types, but lambdas are the primary use case

Example from the forum

Request->OnProccessRequestComplete().BindWeakLambda(this, [this](...)
{
    // Game thread is required to trigger a BP event
    AsyncTask(ENamedThreads::GameThread, [bSuccess]()
    {
        OnConnectResult(bSuccess);
    });
});

Weak binds should be able to default back to null pointers.