nodeInstance Targets not null for deleted nodes

Richard HaseltineRichard Haseltine Posts: 100,747

In answer to a forum query I was trying to write a simple script to select orphaned instances, so as a test I created a couple of spheres, instanced one of them, then deleted the instanced node (which meant that the instance no longer drew). However, the script didn't select the orphan and when I addd a line to print the label of getTarget() it still returned sphere, and getObject still gave a non-null return too. is that correct? It certainly seemed unexpected.

// Find orphaned instances// (c) Richard Haseltine, March 2018// Get al the nodes in the scenevar nodes = Scene.getNodeList();// Go through them looking for instancesfor ( var n = 0 ; n < nodes.length ; n++ ) {	// skip to the next node if this is a non-instance nodes	if ( ! nodes[ n ].inherits( "DzInstanceNode" ) ) {		continue;	}	// check to see if the instance lacks a target	if ( nodes[ n ].getTarget() == null ) {		// select it if it does		nodes[ n ].select( true );	}}

It does work if I save the scene and reload.

Post edited by Richard Haseltine on

Comments

  • jag11jag11 Posts: 885

    Maybe it is still avaliable in case user undoes the delete the operation...

    If I save the scene after delete, clear the scene and load it again, getTarget gives null.

  • Richard HaseltineRichard Haseltine Posts: 100,747

    Yse, I thought Undo support was the most likely explanation - but it seems odd that a "deleted" item is still returned. I don't know if there's a way to query whether the item is marked for deletion once the undo stack bounces it out, or if the behaviour is actually a bug (or an unwelcome necessity)

  • jag11jag11 Posts: 885

    At least oNode.getTarget().isInScene() gives false

  • Richard HaseltineRichard Haseltine Posts: 100,747
    jag11 said:

    At least oNode.getTarget().isInScene() gives false

    Ah, that would be the official way to handle this situation I imagine - thanks.

Sign In or Register to comment.