Assistance needed in using code from a plugin

This is the plugin: GitHub - nutti/UE4-Kdtree: UE4 Plugin: k-d tree

It is an implementation of KD-Trees to better organize (and search on) points in space. It was designed to be used with blueprints and I was using it for this exact use. However, I am converting a lot of my work into C++ now and I need to be able to use this in C++ … which is causing me difficulties.

I am really hoping someone can take the time to download this and look at it to assist with how I might implement it. Here’s what I’ve tried

  1. Adding the include


#include "../Plugins/Kdtree/Source/Kdtree/Public/KdtreeBPLibrary.h"

So, as-is this won’t build. I get the error that it can’t open the include file “KdtreeCommon.h” which is included in the “KdtreeBPLibrary.h”.
To get this to build, I added “Kdtree” to my PublicDependencyModuleNames and PublicIncludePaths



PublicDependencyModuleNames.AddRange(new string] { "Core", "CoreUObject", "Engine", "InputCore", "RuntimeMeshComponent", "Kdtree" });

PublicIncludePaths.AddRange(new string] {"../Plugins/Kdtree/Source/Kdtree/Public" });


  1. Implementing the library
    In my header, I added


UKdtreeBPLibrary *KdLibrary;


to create a new instance of the class. Feels a bit weird to do this but this might just be a hoop I have to jump through to get this “BP” functionality to work in C++.

  1. Building the KD Tree

So, in blueprint, I would call the “Build Kdtree” function which takes an array of vectors and returns a Kdtree structure… which is where I start to get lost. So here’s the blueprint node

And here’s the function from KdtreeBPLibrary.h:




void UKdtreeBPLibrary::BuildKdtree(FKdtree& Tree, const TArray<FVector>& Data)
{
KdtreeInternal::BuildKdtree(&Tree.Internal, Data);
}


So … it’s a void that takes a reference to the Kdtree struct and the array of vectors. This doesn’t match up with the BP function! I don’t know how it’s different. But this seems to mean that I need to create the Kdtree struct prior to calling BuildKdtree.

In the header, I add



FKdtree *KdStruct = new FKdtree;


Then I try to build the Kdtree




TArray<FVector> DemoData;
DemoData.Add(FVector(0,0,0));
KdLibrary->BuildKdtree(*KdStruct, DemoData);


Aaaand problems when building:



  unresolved external symbol "public: static void __cdecl UKdtreeBPLibrary::BuildKdtree(struct FKdtree &,class TArray<struct FVector,class TSizedDefaultAllocator<32> > const &)" (?BuildKdtree@UKdtreeBPLibrary@@SAXAEAUFKdtree@@AEBV?$TArray@UFVector@@V?$TSizedDefaultAllocator@$0CA@@@@@@Z) referenced in function "public: __cdecl AWorldBuilder::AWorldBuilder(void)" (??0AWorldBuilder@@QEAA@XZ)


I’ve always had problems diagnosing these issues, I’m not really sure what part it has an issue with. Maybe it was how I initialized the UKdtreeBPLibrary ? I’m really unsure … especially because I know I’m not using this the way it was intended.

The UKdtreeBPLibrary basically just calls stuff in the private KdtreeInternal which has all the meat of what I need… I’ve tried using that directly but it had its own set of problems. I’m not sure whic problematic method is the better approach. I’m hoping someone a bit more proficient with C++ can help me out here.

The alternative is creating my own implementation of KD-tree which I tried but I had a tough time wrapping my head around the specifics of it and I couldn’t find enough help to get it done.