Are there any downsides to mixing UObject classes with vanilla C++ classes?

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.

Things you don’t put a UPROPERTY() on (must be uclass or primitive) won’t show up in the Editor details panel or be garbage collected. I don’t believe they will save in levels either? Might wanna test that.

So if that isn’t a big deal for what you are doing, then it is fine.

That’s great to hear, thank you!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.