Creating a custom data structure

I need a custom data structure (a tree) so that I can run some path finding logic in my game. I was able to come up with a basic C++ implementation but there are still some open points. If you can answer or provide good documentation references it would help a lot.

So this is what I’m going for:

#pragma once

#include <vector>
#include "TreeNode.h"

template <class T>
using TTreePath = std::vector<TTreeNode<T> *>;

template <class T>
class TTree
{
private:
	TTreeNode<T> *Root;

public:
	TTree();
	~TTree();
	TTreeNode<T> *GetRoot();
	TTreeNode<T> *SetRoot(T Data, int Weight = 0);
	TTreePath<T> FindLightestPath(T TargetData);
};

Questions:

  1. Is this bare C++ implementation the way to go, or should I be using Unreal’s API (maybe UStructs or UObjects)?
  2. What are the concerns regarding memory management of such approach?
  3. Can I unit test this outside of Unreal, directly in Visual Studio?

Thank you

2 Likes
  1. C++ is fine if you are not planning to use or reference it in Blueprint.
  2. If you use UObject as a base class and mark the class properties as UPROPERTY then memory (afaik) will be fully managed by the garbage collector, else you have to manage it yourself.
  3. I’m going to drop some links here as there seems to be a system for this but I haven’t used it myself.
3 Likes

Are you aware that there is a pathfinding system built-in UE?

1 Like

Using NavMesh? I’m not sure if it’s suitable for my case. I want to simulate cars on roads with multiple lane constraints (1-way, 2-way, etc). My idea is to use splines to define the possible paths, and then make the cars select their optimal routes.

1 Like

Splines are OK for this, but some systems like obstacle / vehicle avoidance (if you need those) are already present in NavMesh so a combination in some form could still be useful.

Regarding vehicle avoidance, I was planning to implement some form of AI for each vehicle to decide whether to accelerate or brake, but always sticking to the splines. Since I’m prototyping (and mostly important, learning), I think it’s a good idea to experiment with NavMesh as well. Thanks for your answers!