As an example, I have a base class that holds any type of delegate:
template<class T, typename U>
class MYAPI FMulticast {
public:
TArray<T> DelegateArray;
int Add(const T& Delegate);
int Remove(const T& Delegate);
bool Broadcast(U Value);
};
Then, I inheret those those functions in a child UObject class:
UCLASS(BlueprintType)
class MYAPI UMulticastArrayString : public UObject, public FMulticast<FListenerSignatureArrayString, TArray<FString>>
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadOnly)
TArray<FListenerSignatureArrayString> DelegateArray;
using FMulticast<FListenerSignatureArrayString, TArray<FString>>::Add;
using FMulticast<FListenerSignatureArrayString, TArray<FString>>::Remove;
using FMulticast<FListenerSignatureArrayString, TArray<FString>>::Broadcast;
};
The functions are very basic, with the broadcast function doing:
template<class T, typename U>
inline bool FMulticast<T, U>::Broadcast(U Value)
{
bool bDidBroadcast = DelegateArray.Num() > 0;
for (const T& Delegate : DelegateArray)
{
Delegate.ExecuteIfBound(Value);
}
return bDidBroadcast;
}
Could this approach cause any adverse effects? Is this something that could cause problems with the reflection system, due to the assumptions that the reflection system may make?
I don’t have a good understanding of what Unreal’s systems do under-the-hood, which makes me cautious about mixing a UObject with a regular class.