Jump to content

[SOLVED] delete NodeReference from Editor in runtime


photo

Recommended Posts

Hello.

I noticed that if I use NodeReference in world, then in runtime when I get all the nodes in the world using the following code:

var nodes = new List<Node>();
World.get().getNodes(nodes);

I see that all nodes have duplicates.

For example if the project has NodeReference named A with 2 nested ObjectMeshStatic objects: B and C.

Then in the nodes list we get the following nodes:

  • NodeReference named A,
  • NodeDummy named A - in the amount of 2,
  • ObjectMeshStatic named B - in the amount of 2,
  • ObjectMeshStatic named C - in the amount of 2.

Herewith first NodeDummy object is enabled and second is disabled

Please explain what is the meaning of such duplicates.

 

Next question:

I need to delete NodeReference from world in runtime. I use code like this:

Editor.get().removeNode(nr.getNode());
nr.destroyPtr();
//where nr is NodeReference variable

It seems like it works alright but after that we still have one NodeDummy object in current world. This object is disabled but still present in world and takes memory.

I want to be able to delete NodeReference completely.  How to do this?

 

Edited by kzaharov
Link to comment

Hi!

Herewith first NodeDummy object is enabled and second is disabled
The second one is the cached node. There is only one instance in the World for all NodeReferences the same type. The next time you call "new NodeReference(path)", it will not re-read and parse the file, but simply copied nodes from the cache.

I want to be able to delete NodeReference completely.  How to do this?
You can't remove cached nodes. But, you can use World.get().loadNode(path, cache = 0) to load nodes without adding it to the cache.

P.S. You can use the Editor class to get the list of nodes (without any system and hidden ones).
 

Best regards,
Alexander

 

Link to comment

Oh, you're right. Sorry.

I made a small sample and it works well for me. Look at this:

public override int update()
{
	// press '1' key
	if (App.get().clearKeyState('1') == 1)
	{
		var nodes = new List<Node>();
		World.get().getNodes(nodes);
		Log.message("1) Get current nodes count: " + nodes.Count + "\n");
		
		// for example, i've got "0" - there are no nodes in the world
	}
	
	if (App.get().clearKeyState('2') == 1)
	{
		// create new NodeReference from "NodeDummy.node" file (it was created from empty NodeDummy node)
		NodeReference nr = new NodeReference("NodeDummy.node");
		nr.setName("my_node");
		nr.release();
		Editor.get().addNode(nr.getNode());

		var nodes = new List<Node>();
		World.get().getNodes(nodes);
		Log.message("2) Create NodeReference + cache: " + nodes.Count + "\n");
		
		// now i've got "3":
		//  +1 - NodeReference with name "my_node" (enabled)
		//  +1 - NodeDummy inside my NodeReference (enabled)
		//  +1 - NodeDummy (disabled, cache)
	}
	
	if (App.get().clearKeyState('3') == 1)
	{
		// delete my NodeReference
		Editor.get().removeNode(Editor.get().getNodeByName("my_node"), /* include children */ 1);

		var nodes = new List<Node>();
		World.get().getNodes(nodes);
		Log.message("3) Remove NodeReference: " + nodes.Count + "\n");
		
		// now i've got "1" - there is only one node in the world - cached NodeDummy
	}
	
	if (App.get().clearKeyState('4') == 1)
	{
		// clear cache node
		// The name must be exactly the same as in the NodeReference!
		// If you used absolute path - use absolute path this
		// If you used relative - use relative
		// If you used guid - use guid here
		World.get().clearNode("NodeDummy.node");
	
		var nodes = new List<Node>();
		World.get().getNodes(nodes);
		Log.message("4) Remove cache: " + nodes.Count + "\n");
		
		// now i've got "0" - cache node was successfully removed!
	}

	return 1;
}



Best regards,
Alexander

  • Like 1
Link to comment
  • silent changed the title to [SOLVED] delete NodeReference from Editor in runtime
×
×
  • Create New...