Jump to content

[SOLVED] How to remove added node from editor by code


photo

Recommended Posts

Here I have simple added node to the editor and I'm transferring this nodptr to another global nodeptr as a reference.So i am manging the object with this global nodeptr like movement, rotation and so on.When I'm done with this nodeptr that I added to the editor, I don't want it to appear in the editor anymore, but I can't delete it.

Here is the code,

Nodeptr objectnode2 //this is global node and available in header file as public
Unigine::NodeReferencePtr tobjectnode1 = Unigine::NodeReference::create("External/Entities/STA/Missile_folder/Missile_Left.node");
                tobjectnode1->release();
                Unigine::Editor::get()->addNode(tobjectnode1->getNode(),0);
                objectnode2 = tobjectnode2->getReference();
//----------Above function works correctly, i am able to move the objectnode2------------

Finally i expect below function to delete the node from editor.

void removenodefromeditor(){
	Unigine::Editor::get()->removeNode(object2->getNode(),0);
}

It throw an error and does not delete added node from editor
Editor::removeNode(): 0000018E7942B380 node is not managed by the editor

fFinally It throws an error and does not delete added node from editor
Editor::removeNode(): 0000018E7942B380 node is not managed by the editor

Link to comment

Hi,

You are trying to remove from the Editor objectnode2 (reference of the NodeReference), but the Editor manages the tobjectnode1 (NodeReference itself). NodeReference's content doesn't add to the Editor.

Use this:

void removenodefromeditor()
{
	NodePtr node_reference = objectnode2->getPossessor();
	objectnode2 = NodePtr(); // set ptr to null
	Unigine::Editor::get()->removeNode(node_reference,0);
}


And... If you don't use NodeReference itself, it would be better to use World::get()->loadNode() instead of NodeReference::create(). There is no performance or memory benefits of using NodeReference. It is just containers for the Editor.
 

Best regards,
Alexander

Link to comment
  • silent changed the title to [SOLVED] How to remove added node from editor by code
×
×
  • Create New...