Why isn't my delegate function getting called?

Hello. I’ve been having trouble getting C++ delegates to work.
https://i.imgur.com/9Ta35XQ.png
The delegate bind gets called and from the TilePawn class my logs are telling me the broadcast gets called as well… But SetToFalse is not.

I honestly have no idea how delegates (at least in C++) are supposed to be made based on the documentation alone.

I would love if someone could give me a working super simple no parameter example of C++ delegates working in UE5.

For what I’m actually trying to do: I’m trying to get a set of objects to all update their visibility based on cursor location. Though, right now I’m just trying to get anything to call.

If you feel I’m leaving important information out let me know, I’m posting this way late at night before I go to bed and may have missed something.

EDIT: Everything relevant from the other file:

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FTurnOffVisibility);

UFUNCTION(BlueprintCallable)
void TurnOffTowerVisibility();

FTurnOffVisibility TurnOffTurretVis;

void ATilePawn::TurnOffTowerVisibility()
{
UE_LOG(LogTemp, Warning, TEXT(“Broadcast called;”));
TurnOffTurretVis.Broadcast();
}

Do you have this?

UFUNCTION()
void setToFalse();

Have to have ufunction for any function that’s called from timers and delegates or the system won’t see it. I missed a ufunction and the game crashed.

6 Likes

You need to tell the delegate what to call when someone calls Broadcast() on the delegate, you are missing something like

TurnOffTurretVis.AddUObject( ATurret, &ATurret:TurnOffTowerVisibility )

Oh, yep, that’s it. It was just missing UFUNCTION(). Thank you so much man!

This got me too! Adding the UFUNCTION specifier fixed it! thanks!!

This is definitely worth knowing. The problem is that if you don’t have UFUNCTION here, the project won’t fail to compile, and you’ll get no errors or warnings in the editor either. You’re just left wondering why your function isn’t being called.

Also, in many of the tutorials I’ve followed (like this one: [Tutorial] Creating and Using Delegates C++ and Accessing them in Blueprints), and in the official docs, the importance of this isn’t specified.