Regular structs and garbage collection

I need to use templated structs, which is not possible with UStruct. Will the regular struct below prevent garbage collection?

struct A
{
UPROPERTY()

AActor* actor;

UPROPERTY()
UClass* SomeDerivedUClass;

}

Hi,

The struct needs to be exposed to the reflection system in order to be automatically exposed to the garbage collector, i.e. it needs to be a USTRUCT.

However, instead you might want to consider inheriting FGCObject, overriding the AddReferencedObjects function and then passing your UObject* members directly to the collector:

struct A : public FGCObject
{
    AActor* actor;
    UClass* SomeDerivedUClass;

    virtual void AddReferencedObjects(FReferenceCollector& Collector) override
    {
        Collector.AddReferencedObject(actor);
        Collector.AddReferencedObject(SomeDerivedUClass);
    }
}

Hope this helps,

Steve

Thanks.

I note that your actor and derived class are not tagged UProperty(). Not possible without a UStruct or UClass wrapper?

Correct. UPROPERTY() markup is only meaningful inside a UCLASS() or USTRUCT().

Steve

It should be fine. Plenty of our classes inherit FGCObject in addition to other bases (particularly tickables). CRTP shouldn’t affect anything.

Steve

I want to create an inheritance structure that uses the curiously recurring template pattern (CRTP).

Can you think of any potential issues if I inherit from both FGCObject and FTickableGameObject?