Struct with member tarray of itself

PrettyTrue
Sat, 13 Feb 2021 15:19:37 +0000
Editor Scripting

In standard C++, we can use vectors and maps as a means of a tree structure

struct Foo
{
    Foo();
    std::vector<Foo> subfoos;
};

But TArray/TMap cannot do this (by design). Is there a standard approach for handling this within Unreal’s syntax? The use case would be something like items that have their own inventory of items, etc.

USTRUCT()
struct Foo
{
    GENERATED_BODY()
    Foo();

    UPROPERTY()
    TArray<Foo> SubFoos; // No can do! :grimmace:
};

The only estimate I could come up with is holding some store of these structures and using a pointer to them. But as I currently understand the system that doesn’t hold up with replication.

Thanks so much!

2 posts - 1 participant