Help with adding CollisionNodes as children to a node [Edited Title]

I initially wanted to have this post deleted, but after Thaumaturge left a comment, I realized that even if I had truely found a solution, it may not be the most efficient one.

Essentially, I’m trying to create a custom class that inherits from ActorNode that; upon construction and destruction; properly manages it’s own associated collision Solids and Nodes.

It’s worth noting that aside from the fact that this is my first foray into the c++ side of panda3d, I’m also fairly inexperienced with c++, so I worry that I might be overlooking something simple.

That being said, this is what I have so far:

#pragma once

#include "actorNode.h"
#include "collisionBox.h"
#include "collisionNode.h"

class playerEntBase : public ActorNode


	CollisionNode boxNode("collisionBumpHolder");
	PT(CollisionBox) hitbox = new CollisionBox(const LPoint3(0, 0, 0),PN_stdfloat(6),PN_stdfloat(6),PN_stdfloat(9.75));


The part I’m struggling with is this->add_child(boxnode), where I’m given an error ‘No suitable conversion from “CollisionNode” to “PandaNode” exists’.
On top of being generally confused, I’m now worried Visual Studio is going to yell at me when I try to build.

To try and summarize my question, What’s the best way of attaching “sub-nodes” in C++? Should I be concerned about errors involving classes that inherit from the classes that are accepted?

Edit: fixed code in post to reflect fix I made literally just after rewriting this post

Might the solution perhaps be useful to someone else with the same problem? If so, it might be worth keeping!

Thanks for the encouragement, Helped me realize that I might not have solved it on my own after all.
I’ve re-phrased the original question with more detail.

1 Like

The issue turned out to be that I was this->add_child(boxNode) expects a pointer to a pandaNode, not the pandaNode itself.

In the end, this probably was primarily due to my inexperience. To be specific, I was confused by a variable initialized as a pointer to a collisionSolid but another variable just being an actual collisonNode in the documentation.

1 Like

For the record, you should never do this to a class that inherits from ReferenceCount, because Panda expects to manage the lifetime of this object via its reference counting system and bad things will happen if it gets passed to other places.

Always do:

PT(CollisionNode) boxNode = new CollisionNode("collisionBumpHolder");