Can anyone explain how to use TOctree in UE4?

So i looked at the documentation and it didn’t tell me too much.

I looked at the Engine Source for examples but i couldn’t figure out what OctreeSemantics and FOctreeElementId is?

Can anyone give me some examples how to define a custom Octrees in UE4 using the TOctree class. And/Or explain what those types are used for?

Thanks in advance!

I’d look at NavigationOctree.h and PrimitiveSceneInfo.h if you want to see how TOctree is used.

OctreeSemantics describe various behaviors of the Octree, maximum elements per leaf, how to compare two elements, the bounding volume for an element, etc.

FOctreeElementId is an ID that you can use to do constant time look ups into Octree to add/remove/get an object (rather than having to search for it using a bounding volume or iterator).

myOctree.GetElementById(myOctreeElementId); // Returns a reference to the object as long as that ID is valid, which you can check by calling myOctreeElementId.IsValidId()

// Do stuff

// Clean up

// Define the custom octree

struct FExampleElement
       int32 Index;

       FBoxCenterAndExtent BoxCenterAndExtent;
 struct FExampleSemantics
         enum { MaxElementsPerLeaf = 16 };
         enum { MinInclusiveElementsPerNode = 7 };
         enum { MaxNodeDepth = 12 };
         typedef TInlineAllocator<MaxElementsPerLeaf> ElementAllocator;
         FORCEINLINE static FBoxCenterAndExtent GetBoundingBox(const FExampleElement* Element)
             return Element->BoxCenterAndExtent;
         FORCEINLINE static bool AreElementsEqual(const FExampleElement* A, const FExampleElement* B)
             return A.Index == B.Index;
         /** Ignored for this implementation */
         FORCEINLINE static void SetElementId(const FVertex* Element, FExampleElementId Id){}
 typedef TOctree<FExampleElement*, FExampleSemantics> FExampleOctree;

// Initialization

FBox Bounds;
TUniquePtr<FExampleOctree> ExampleOctree = = MakeUnique<FExampleOctree>(