Jump to content

Remove and Add node again


photo

Recommended Posts

Posted

I need realize next logic:

1. player can get some game's objects in his inventory, and this nodes must remove from world;

2. player can throw out objects from inventory back to world.

 

I try use next code, cut from world:

int intersectionResult[0];
Object selectedNode = engine.world.getIntersection(p0, p2, ~0, intersectionResult);

engine.editor.removeNode(selectedNode);

objects.append(selectedNode);

 

Add back to world:

Object object = objects[index];

engine.editor.addNode(object);

 

objects - is array that accumulate objects, cut from worlds.

 

When I use addNode() nothing is happens (added object not appear in world), when I use it again, throws error:

Editor::addNode(): 000000000321D280 node is already defined

 

What I'm doing wrong? Thanks

Posted

What I'm doing wrong? Thanks

 

Not sure but maybe you should use engine.editor.release() instead of engine.editor.remove() for transfer of the selected node from editor to you script module. After the node is released from editor via engine.editor.release(), it must be appended to your script via node_append(). Otherwise, it will cause memory leak. Have a look into documentation for engine.editor.release()/remove() and section

 

Programming\C++ API\Memory Management

 

int intersectionResult[0];
Object selectedNode = engine.world.getIntersection(p0, p2, ~0, intersectionResult);

if( selectedNode != 0 )
{
   engine.editor.releaseNode(selectedNode);

   objects.append( node_append(selectedNode) );
}

 

Add back to world:

Object object = objects[index];

engine.editor.addNode( node_remove(object) );

// shouldn't object be removed from objects[] ?

Posted

I try use engine.editor.releaseNode(selectedNode); - but object not disappear from world:

 

engine.editor.releaseNode(selectedNode);

objects.append(node_append(selectedNode));

 

This functional pass ownership from editor to script... but object stay in world, and I need to remove object - it's must "move" to user inventory.

 

// shouldn't object be removed from objects[] ?

 

Yes, it must removed from objects array. Thanks

Posted

This functional pass ownership from editor to script... but object stay in world, and I need to remove object - it's must "move" to user inventory.

 

I guess it should be removed visually from world, right ? So what about just simply calling node.setEnabled(0) on move to user inventory and node.setEnabled(1) on move back to world ? This might do the trick without any complex node ownership transfer at all.

Posted

Yes, it's fine solution! Thanks!

×
×
  • Create New...