How to properly get the leaves of Chaos::TAABBTree

I want to get the leaves of the AABBTree but it seems there is no way to get it?

[Image Removed]

Error C2243 : ‘type cast’: conversion from ‘const Chaos::TLeafContainer<Chaos::TAABBTreeLeafArray<Chaos::FAccelerationStructureHandle,true,Chaos::FReal>> *’ to ‘const TArray<Chaos::TAABBTreeLeafArray<Chaos::FAccelerationStructureHandle,true,Chaos::FReal>,FDefaultAllocator> &’ exists, but is inaccessible

Maybe because such type of TLeafContainer is privately inherited from TArray which the TAABBTree::GetLeaves returns?

[Image Removed]

[Image Removed]

Hello [mention removed]​,

The compile error is indeed caused by the specialization of TLeafContainer used by TAABBTreeLeafArray<FAccelerationStructureHandle, true, FReal>. In that specialization the container privately inherits so the implicit conversion that GetLeaves() performs when returning a const TArray& becomes inaccesible.

A workaround for this would be to implement an engine-side fix to add an AsArray() method inside TLeafContainer that explicitly returns its TArray base and then have TAABBTree::GetLeaves() call Leaves.AsArray() instead of returning Leaves directly. This preserves the existing API and avoids the private-inheritance restriction.

Add to the default container (TLeafContainer) (AABBTree.h)

class TLeafContainer : public TArray<LeafType>
{
public:
    const TArray<LeafType>& AsArray() const
    {
        return *static_cast<const TArray<LeafType>*>(this);
    }
};

Add to the specialized container. (AABBTree.h)

// Here we are specializing the behaviour of our leaf container
template<>
class TLeafContainer<TAABBTreeLeafArray<FAccelerationStructureHandle, true, FReal>>
    : private TArray<TAABBTreeLeafArray<FAccelerationStructureHandle, true, FReal>>
{
public:
    const FParent& AsArray() const
    {
        return *static_cast<const FParent*>(this);
    }
};

Modify TAABBTree::GetLeaves() (AABBTree.h)

const TArray<TLeafType>& GetLeaves() const { return Leaves.AsArray(); }This will allow compilation for the following line:

const TArray<LeafType>& Leaves = Tree->GetLeaves();Please let me know if this information helps your case.

Best,

Francisco