Spawn Actor from AActor derived class

I am implementing procedural level generation using a binary space partitioning algorithm that spawns arbitrary actors within each node, similar to Unreal Engine 4 Training Twitch: Procedural Room Generation.

My AtidLeafNode class derives from AActor as it needs a position vector to determine where the node is in the world and thus calculate the bounds of which it can spawn an actor. It has two private member variables:

	AtidLeafNode* LeftChild;

	AtidLeafNode* RightChild;

I have a member function Split() which continually breaks down the root LeafNode to create smaller ones. So inside the function I need to make several calls to SpawnActor as such:

LeftChild = a_World->SpawnActor(AtidLeafNode::StaticClass());
RightChild = a_World->SpawnActor(AtidLeafNode::StaticClass());

These lines throw me a compiler error: “2 overloads have no legal conversion for ‘this’ pointer.”
I have tried other custom typed AActors with no luck as well.

According to 14 - Coding What, Where, and When to Spawn you are able to spawn actors from inside an actor. What am I doing wrong?


Ahh, that was experimental. I do indeed have the template type before the function parenthesis. The same error still remains.

have you tried passing in FActorSpawnParameters SpawnInfo?

have you tried making the variables public?

shouldn’t the T in ATidLeafNode be capitalized?

Oh dear, I just discovered the mistake by chance when I was shifting around my code so that I could paste it in a more stripped down format.

Here’s the offending code:

if (const UWorld* a_World = Tree->tidGetWorld())
 // Spawns...

Where it should be:

if (UWorld* const a_World = Tree->tidGetWorld())

It should be according to UE4 code standards. But when I created the github repo I naturally made it lowercase. I’ll probably refactor the class names at some point, I’ll admit it’s tedious to read and type.