Download

Using Delegates

Hello, I have a character and a movement component. Using delegates I would like the movement component to call a function on the character, but I just can’t get it working.

Movement Component h


DECLARE_DYNAMIC_MULTICAST_DELEGATE(FMovementUpdated);

UCLASS()
....
	FMovementUpdated MovementUpdated;
};

Movement Component cpp


MovementUpdated.Broadcast();

Unit.cpp



void AUnit::BeginPlay(){
MovementComponent->MovementUpdated.AddDynamic(this, &AUnit::UnitMovementUpdated);
}

This builds however AUnit::UnitMovementUpdated is never called.

I tried using DECLARE_DELEGATE, ExecuteIfBound, and BindSP, and a bunch others I found online, but same deal, never called.

I have no idea what’s wrong, any ideas?

Edit: MovementUpdated.IsBound() returns true, yet it still never calls UnitMovementUpdated.

Try this out real quick change MovementComponent->MovementUpdated.AddDynamic(this, &AUnit::UnitMovementUpdated); to just MovementUpdated.AddDynamic(this, &AUnit::UnitMovementUpdated);

Have you tried binding the function in the constructor?

This doesn’t work because MovementUpdated doesn’t exist in the class, it exists in the MovementComponent class.

Yes, it makes no difference.

This is strange because I’ve used things like
FootCollider->OnComponentBeginOverlap.AddDynamic(this, &AHero::FootOverlap);
(FootCollider is a USphereComponent component)

and it works just fine, but I can’t get my own custom one to trigger.

Edit: I tried setting it to UPROPERTY(BlueprintAssignable) FMovementUpdated MovementUpdated;
but that didn’t help. I looked at how OnComponentBeginOverlap is setup and used in UPrimitiveComponent, and my setup looks identical, so I really have no ideas here.