My game delegates have broken

Hello
We are using UnrealEngine since version 4.1, for our commercial project, right now we are on 4.6.1, we have ONLY used release versions of the engine.

Well, after saying this, I’m going to explain my problem:

One week ago, some of our maps started to giving us problems, lots of the delegates that we used in our level blueprints, are broken and if I try to:

  1. Delete the delegate box, Unreal crashes
  2. Save the map, UnrealCrashes.
  3. Play, UnrealCrashes.

Debugging from visual studio I found the function that crashes on ScriptDelegates.cpp

void RemoveInternal( const TScriptDelegate<TWeakPtr>& InDelegate ) const
	{
		const int32 NumFunctions = InvocationList.Num();
		for( int32 CurFunctionIndex = 0; CurFunctionIndex < NumFunctions; ++CurFunctionIndex )
		{
			if( InvocationList[ CurFunctionIndex ] == InDelegate )
			{
				InvocationList.RemoveAtSwap( CurFunctionIndex );

				// No need to continue, as we never allow the same delegate to be bound twice
					break;
			}
		}
	}

This line crashes: const int32 NumFunctions = InvocationList.Num();

Because InvocationList = NULL

Yesterday we tried to fix this by deleting the actor, and then deleting the delegate (This worked) but, when we restarted the editor, the problem appeared again.

Right now our project is very big, and we can’t redo all the maps again (This bug doesn’t appear in all maps).

If you need something to track this bug, ask for It, i will help with anything you need to fix this issue.

In this picture you can see where it crashes:

One more thing, some of the delegates that failed in those maps, changed their names from (For example):

OnBeginOverlap(TriggerBox39)

to:

OnBeginOverlap(TriggerBox-1)

Bit if I right click on the delegate and select Find actor in level it takes me to the right actor.

Thanks in advance for your time.

EDIT:

Well, finally I have updated to the last 4.7 version from Github and the problem persists…

If I try to compile the level, the engine crashes in BlueprintEditorUtils,cpp in this function:

bool FBlueprintEditorUtils::FixLevelScriptActorBindings(ALevelScriptActor* LevelScriptActor, const ULevelScriptBlueprint* ScriptBlueprint)

When it tries to get the target delegate from the event node, the TargetDelegated = NULL, so when it makes the check it crashes…

// Grab the MC delegate we need to add to
FMulticastScriptDelegate* TargetDelegate = EventNode->GetTargetDelegate();
check(TargetDelegate); //<-CRASH

I tried to duplicate the map but it crashes too. The only way I can do something is by deleting the actor first and then I can safely delete the event delegate related to that actor.

I have modifyed this part of the function:

if( LevelScriptActor->FindFunction(TargetFunction) )
				{
					// Grab the MC delegate we need to add to
					FMulticastScriptDelegate* TargetDelegate = EventNode->GetTargetDelegate();
					check(TargetDelegate);

					// Create the delegate, and add it if it doesn't already exist
					FScriptDelegate Delegate;
					Delegate.BindUFunction(LevelScriptActor, TargetFunction);
					TargetDelegate->AddUnique(Delegate);
				}

To this:

 if( LevelScriptActor->FindFunction(TargetFunction) )
    {
    	// Grab the MC delegate we need to add to
    	FMulticastScriptDelegate* TargetDelegate = EventNode->GetTargetDelegate();
    
        //check(TargetDelegate);
    
        if (TargetDelegate){
          // Create the delegate, and add it if it doesn't already exist
          FScriptDelegate Delegate;
          Delegate.BindUFunction(LevelScriptActor, TargetFunction);
          TargetDelegate->AddUnique(Delegate);
        }
        else{
           FString log = EventNode ? EventNode->GetName() + "(" + EventNode->EventOwner->GetName()+")" : TEXT("unknown");
           UE_LOG(LogBlueprint, Warning, TEXT("TargetDelegate for node %s is = NULL"), *log);
           bWasSuccessful = false;
        }
    }

This fixes nothing but at least I can see wich delegates are broken.

I will try to replace the actors and their delegates to see if they work again .

Hey Yannick-

Delegate issues have been reported and we are currently investigating what the cause may be and possible solutions. Once there is a solution that does not disrupt other aspects of the engine it will be implemented. For the time being, let us know if replacing the actors and delegates helps you with your project

Cheers

Hey, thaks for the answer.

Yes, replacing the actors and created again the delegates seems to fix the problem. The strange thing is that I MUST delete the actor before deleting the delegates or it crashes… (I don’t know if this info will help you to find the problem).

Thanks for your time.