Jump to content

[SOLVED] How to add a child to a node.


photo

Recommended Posts

Hi, I have a node that I want to parent other nodes so I can move them all around as a group and so the child node space is relative to the parent node.

 

I'm just not sure I understand how the API works around this.

 

I've created a light like this:

 

omniLight = LightOmni::create(/*params*/);

 

and then later I add the omniLight to my parent

 

parentNode->addChild(NodePtr(light->omniLight.get()));

 

and then if I use omniLight later, like:

 

omniLight->setEnabled(true);

 

it crashes.

 

So I figure at the time I am passing the omniLight to the addChild, creating a new NodePtr there must be releasing the old one.  So if it does that, but addChild only takes a NodePtr, how am I supposed to do this correctly?  Is there some special way I'm supposed to cast this?  Or am I just no longer supposed to use the original omniLight Ptr after I've passed it as a child?  I want to keep omniLight around later for easy access to the light.

 

Thanks

Link to comment

Hi Joseph,

 

yes, when you create NodePtr instance, it is owning resource, deleting it on destruction. To get not owning Ptr call Node::getNode() like this:

parentNode->addChild(omniLight->getNode());
Link to comment
×
×
  • Create New...