Jump to content

[SOLVED] Breaking node reference


photo

Recommended Posts

Posted

Currently it is possible to save out a node as a NodeReference, add it to levels, and have them update everywhere when saved which is awesome. In some cases, though, we wish to add a NodeReference Node, but then make it unique. Is there a way to convert these from NodeReference back to normal unique Node objects in the world?

  • Like 1
Posted

Is there a way to convert these from NodeReference back to normal unique Node objects in the world?

 

Might be possible via UNIGINE scripting. Write an appropriate script function e.g. convertNodeReference and add it to console, so you artist can invoke this conversion interactivly via console. Something like the following snippet (NOT tested, so expect errors, but should show principle).

 

I am not sure if there are any issues with referenced node material/property libraries within external node file, as these most probably also will have to be added to loaded world for proper material/property assignment on world reload. You have to test it.

 

#include <core/unigine.h>
#include <core/scripts/system.h>

int init() {

  engine.console.addCommand("convertNodeReference ",
                            "convertNodeReference <node_reference_name>  convert node_reference to node instance",
                            "convertNodeReference");
  return 1;
}

int shutdown() { return 1; }
int update()   { return 1; }


void convertNodeReference ( string node_reference_name )
{
   Node node = engine.editor.getNodeByName( node_reference_name );

   if( node != 0 )
   {
       NodeReference node_reference = node_cast(node);

       if( node_reference != 0 )
       {
           Node node_referenced = node_reference.getNode();
           Node node_clone      = node_referenced.clone();

           node_clone.setName( node_reference_name + "_instance" );
           node_clone.setParent( node_reference.getParent() );
           node_clone.setWorldTransform( node_reference.getWorldTransform() * node_referenced.getTransform() );

           engine.editor.addNode( node_clone );
           engine.editor.removeNode( node_reference );
       }
   }
}

Posted

I should add this to the feature request area... as it seems like a must have with this system.

Posted

There is an "import node" button near the "load node reference" button. You can import node reference into the world tree and modify it.

×
×
  • Create New...