So I have an event tickMinute in my world logic class, and I’m trying to set it up so whenever that event broadcasts, functions in other actors execute:
//world.h:
DECLARE_EVENT(AWorld, FTimePasses)
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class MYGAME_API AWorld : public AActor{
GENERATED_BODY()
public:
FTimePasses tickMinute;
}
//external actor component UConsumable:
void UConsumable::RegisterWithClock(){
AWorld* world;
for (TActorIterator<AWorld> ActorItr(GetWorld()); ActorItr; ++ActorItr)
{
world = *ActorItr;
}
if (world != nullptr){ //Get reference to the actor whose event we want to subscribe to
world->tickMinute.Add(this, &UConsumable::procConsumable); //set procConsumable to fire every time tickMinute broadcasts
}
}
The last line is what I’m having trouble with- I’m trying to run Add with the memory address of the function I want to subscribe to the event, but it won’t compile, instead producing an error, “cannot convert from ‘void (__cdecl UConsumable::* )(void)’ to ‘const FName’”. I know that means my argument is wrong, but it seems weird that it would want an FName instead of a function reference, is .Add() the wrong thing to use when I’m subscribing to events?