21.8 C
New York
Friday, September 5, 2025

c++ – Specifying a “default worth” for parameters when binding capabilities to delegates?


As an instance I’ve a category UFoo which has a dynamic delegate myDelegate with no parameters. I can’t modify the contents of UFoo in any manner.

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FMyDelegate);

UCLASS()
class UFoo : public UObject
{
    GENERATED_BODY()

public:
    UPROPERTY()
    FMyDelegate myDelegate;

    // remainder of class
}

I even have a category UBar which comprises three UFoo-type objects foo1, foo2 and foo3. UBar additionally has a operate DoStuff(int32 num) which takes a single integer as a parameter.

UCLASS()
class UBar : public UObject
{
    GENERATED_BODY()

public:
    UFUNCTION()
    void DoStuff(int32 num);

    UPROPERTY()
    TObjectPtr foo1;

    UPROPERTY()
    TObjectPtr foo2;

    UPROPERTY()
    TObjectPtr foo3;

    // remainder of class
}

I wish to bind DoStuff to the myDelegate delegate of foo1, foo2 and foo3. However as a result of the record of parameters is totally different between the delegate and DoStuff, this clearly can’t be accomplished as is.

That being mentioned, I do know that within the case of foo1‘s delegate, the integer worth handed to DoStuff ought to at all times be 1. Likewise, it needs to be 2 for foo2, and three for foo3. In that case, does this develop into doable? Is there a method to specify a default parameter worth of types for DoStuff that’s totally different per UFoo occasion, permitting me to bind DoStuff to their delegates regardless of the differing parameter lists?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles