Description

Changing the name of a function that is bound to a delegate, or attempting to bind a delegate to a second function, causes the new/changed function to not be called when the delegate is triggered.

Steps to Reproduce
  1. Open UE4 Editor (any project)
  2. Add code to project based on Actor (MyActor)
  3. Add the following to MyActor.h
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Test)
    		UBoxComponent* TestBox;
    
    	UFUNCTION(BlueprintCallable, Category = Test)
    		void OriginalFunction(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);
    
  4. Add the following to MyActor.cpp
    • #include "Engine.h"
    • Add to AMyActor constructor
      	TestBox = CreateDefaultSubobject<UBoxComponent>(TEXT("TestBox"));
      	RootComponent = TestBox;
      	TestBox->OnComponentBeginOverlap.AddDynamic(this, &AMyActor::OriginalFunction);
      
    • Add below tick function declaration
      void AMyActor::OriginalFunction(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
      {
      	if (GEngine)
      	{
      		GEngine->AddOnScreenDebugMessage(-1, 4.f, FColor::Magenta, TEXT("OriginalFunction"));
      	}
      }
      
  5. Compile
  6. Add instance of the class to the level
  7. PIE & walk into the box
    • Note that the message is printed to the screen
  8. In code, change all instances of "OriginalFunction" to "ChangedName"
    • 1 change in .h file - 3 changes in .cpp (AddDynamic/FunctionName/TEXT macro)
  9. Compile
  10. PIE again

Result:
When walking into the box after changing the function name, the debug message does not appear

Expected:
Delegate is still able to recognize the bound function after changing the function name

Have Comments or More Details?

Head over to the existing Questions & Answers thread and let us know what's up.

28
Login to Vote

Won't Fix
ComponentUE - Foundation - Core
Affects Versions4.13.24.14
CreatedNov 9, 2016
ResolvedJun 16, 2017
UpdatedJul 14, 2021
View Jira Issue