# How can I correctly instantiate an octree in UE4?

I tried to create a simple Octree like this: (I looked at the FMeshTriOctree source code since no question in answers.unrealengine.com helped me)

// My FVertex class is slightly more complexe, but let's say it's something like this:
class FVertex : public FVector
{
int32 ID;
}

struct FVertexOctreeSemantics
{
enum { MaxElementsPerLeaf = 16 };
enum { MinInclusiveElementsPerNode = 7 };
enum { MaxNodeDepth = 12 };

typedef TInlineAllocator<MaxElementsPerLeaf> ElementAllocator;

FORCEINLINE static FBoxCenterAndExtent GetBoundingBox(const PBS::FVertex* Vertex)
{
return FBoxCenterAndExtent(Vertex->GetBoundingBox());
}

FORCEINLINE static bool AreElementsEqual(const PBS::FVertex* A, const PBS::FVertex* B)
{
return A==B;
}

/** Ignored for this implementation */
FORCEINLINE static void SetElementId(const PBS::FVertex* Element, FOctreeElementId Id){}
};

typedef TOctree<PBS::FVertex*, FVertexOctreeSemantics> FVOctree;


But when I instanciate my octree it returns:

Fatal error: [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.9\Engine\Source\Runtime\Core\Private\Misc\CoreMisc.cpp] [Line: 975]
The TOctree() constructor is for internal usage only for hot-reload purposes. Please do NOT use it.


What can I do?

The error is telling you that the default constructor of TOctree isn't something you're supposed to use directly. Instead, use a different constructor. You probably want to use the one that takes a center point and an extent:

TOctree(const FVector& InOrigin,float InExtent)


If you notice, the example source code you linked to stores a pointer to the octree type:

TUniquePtr<FMeshTriOctree> MeshTriOctree;


which it then instantiates as

MeshTriOctree = MakeUnique<FMeshTriOctree>(
Bounds.GetCenter(),
Bounds.GetExtent().GetMax()
);


The default constructor is only available when building with hot-reload constructors enabled; if you were to disable that option you'll get a regular old compile error, so you shouldn't rely on that constructors existence.