Download

Exposing USTRUCT() when in a pointer type

Hi guys, I have some questions about how to allow for the editing of a USTRUCT()'s UPROPERTY() when it is exposed as a pointer type.
USTRUCTS(), from what I am aware of, have member reflection. So why cant we reflect upon them in the editor, because they aren’t ref counted?
That could be solved by TSharedPtr<>… but that doesnt work.

How can I expose this as editable if I cant give it the pointer the UPROPERTY() tag? There has to be a way, the weight of UObject is completely unnecessary as overhead for FNode().

Thanks.



USTRUCT()


USTRUCT()
struct FNode()
{
    GENERATED_BODY()

    UPROPERTY()
    bool SomeBoolean;
}

UCLASS()
class UGraph() : public UObject
{
    // How can I get the editor to expose the members of FNode when its a pointer?

    UPROPERTY() // Not allowed
    FNode* node;

    UPROPERTY() // Havent tried this, I doubt it will work either
    TSharedPtr<FNode> node;
}


Classes deriving from UObject (UCLASS) are the only “pointer” types that the reflection system understands, this is because they are tightly integrated with the Garbage Collection system, among other restrictions.

I too weighed up the differences, essentially, as long as you aren’t “churning” UObjects, the extra overhead isn’t that great.

Alternatively, you could write a custom serialization function and handle serializing the nodes yourself, and also write a details panel customization for the UGraph object in order to show them in editor. But, that will be a mountain of probably quite error-prone work.

Yeah as said above pointers to USTRUCTS() aren’t supported - any type of exposed/GC’d object needs to use the UObject type.

TSharedPtr does not support UPROPERTY either since it reference any arbitrary data. UObjects don’t have much overhead. Things like graph nodes in the blueprint editor are made up of multiple UObjects, for pins and suchlike.

Actually, the EdGraph and EdNodes are UObjects, but the runtime graph is all UStructs() for performance.

I find it silly that it cant reflect upon USTRUCTS, which have property reflection.

Yeah that’s what I mean, the nodes and pins are all individual UObjects which is fine for an edit-time tool.

But yeah TL;DR, can’t have reflected pointers to structs, only UCLASS()