Jump to content

GetNodeByName does not find NodeReference


photo

Recommended Posts

Posted

Hello,

engine.editor.getNodeByName("xxx"); does not return the NodeReference to my existing xxx NodeReference in my scene.

If I do a loop through all nodes, then the NodeReference is correctly found.

forloop(int i = 0; engine.editor.getNumNodes()) {
	Node node = engine.editor.getNode(i);
	Node target_node = node;
	if(target_node.getType() == NODE_REFERENCE) {
		NodeReference reference = node_cast(target_node);
		target_node = reference.getReference();
		if (target_node.getName()=="xxx")
			log.message("%s\n",target_node.getName()); // The node is correctly found
	}
}

Node xxx = engine.editor.getNodeByName("xxx");
log.message("%s\n",xxx.getName()); // xxx is null: the node is not found

Is it a bug or did I miss something ?

Posted

Hello,

Snipets are not equal. The first one searching for the root node of NodeReference and the second one can only find NodeReference itself but not its content. If NodeReference itself has known name it can be found by editor and then you can get its root node.

Posted

Here is a step by step repro:

- create/primitive/box and rename it "xxx"

- right-click/Create a NodeReference (named "xxx")

-run the previous script in a WorldExpression (add the line #include <core/scripts/utils.h> at the top), enclosed in "{ }"

-result is: 

Quote

xxx  <<< printed by the log.message in the loop

ExternClass::run_function(): object is NULL in "class Node * __ptr64" class    <<< printed by the getNodeByName

So getNodeByName can't find nor the NodeReference's Reference node, nor the Node corresponding to the NodeReference.

Posted

I've reproduced this behaviour. World reloading fixes it so it shouldn't be an issue at runtime. I believe that's an editor bug that NodeReference can't be found by name right after creation like other types of node.

Posted

Agreed.

If I drop the ".node" file in the scene, then both works. But if I "Edit" the NodeReference  and then click "Cancel" or "Apply" then the getNodeByName doesn't work any more.

The problem is not for runtime, but during the development time, in editor ! Because it breaks the workflow, I think it should be fixed.

×
×
  • Create New...