UE4 Delegate, Suddenly unbounded in runtime

public_float_hp
Mon, 03 Jan 2022 16:13:46 +0000
C++

Hello, In my project, there is a class which has a delegate as a member variable.
My CharacterClass has that class and some function would be bound with the delegate in the class.

Q. Suddenly, the binding is unbound. What happened to this? It seems that GC activated but I don’t understand clearly.

Here is my ClassA.h

UCLASS()
class SECONDARYPRACTICE2_API UClassA : public UObject
{
	GENERATED_BODY()
public:
	FVoidNotier Notier; //FVoidNotier is a delegate created by DECLARE_DELEGATE
};

Here are my CharacterClass’s BeginPlay( ) and Tick( )

void ASecondaryPractice2Character::BeginPlay()
{
	Super::BeginPlay();
	ClassA = NewObject<UClassA>();
	ClassA->Notier.BindLambda([=]() {UE_LOG(LogTemp, Warning, TEXT("Calling from ClassA")); });
}

void ASecondaryPractice2Character::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	if (ClassA == nullptr)
	{
		UE_LOG(LogTemp, Warning, TEXT("ClassA is Null"));
	}
	else
	{
		if (ClassA->Notier.IsBound() == false)
		{
			UE_LOG(LogTemp, Warning, TEXT("ClassA's Delegate is not bound@@@@"));
		}
		else
		{
			ClassA->Notier.ExecuteIfBound();
		}
	}
}

As long as ClassA is not null and ClassA’s Delegate is bound, “Calling from ClassA” would be printed. But suddenly, “ClassA’s Delegate is not bound@@@@” is being printed…

What happened to this?

5 posts - 2 participants