Jump to content

Create node with NodeReferance and assign it to Nodeptr


photo

Recommended Posts

Hello everyone,

Unfortunately i couldn't assign a node to nodeptr which is created by nodereference in c++.Basically i want to do is to create a available object1 node with nodereference and assign it to node object3 ptr.Then I would like to set its rotation to available node object2 in editor.Finally i will disable this node object2 from editor.Therefore node object3 that is assigned and created by object 2 nodereference will be a new object instead of object2.

Here is the code to clarify this issue:

Unigine::NodePtr object2 = Util::Search::getNodeRecursive("Object2",Object2parent);
Unigine::NodePtr object3;

Unigine::NodeReferencePtr object1 = Unigine::NodeReference::create("External/Entities/object1.node");
qDebug()<<object1->getNodeName();
object3 = object1->getNode();
object3->setWorldRotation(Object2->getWorldRotation()); //Object2 is available in unigine editor and set in apropriate position,i want to use object3 as newone
object2->setEnabled(false);//I want to destroy or disable this object which is available in unigine editor and use object1 as new one

Unfortunately program close itself immediately without of any error.

Any help will be apreciated.

Edited by burakdogancay
Link to comment

try so

Unigine::NodePtr object2 = Util::Search::getNodeRecursive("Object2",Object2parent);
Unigine::NodePtr object3;

Unigine::NodeReferencePtr object1 = Unigine::NodeReference::create("External/Entities/object1.node");

//release Ptr and give it to the editor.
object1->release();
Editor::get()->addNode(object1->getNode());
//

qDebug()<<object1->getNodeName();
object3 = object1->getNode();
object3->setWorldRotation(Object2->getWorldRotation()); //Object2 is available in unigine editor and set in apropriate position,i want to use object3 as newone
//object2->setEnabled(false);//I want to destroy or disable this object which is available in unigine editor and use object1 as new one

// for remove node
Editor::get()->removeNode(object2);

may be it will help you

Link to comment

Thank you for your response, i think it adds object1 to the editor.But I would like to set it drectly to object2 position.

I checked object2 position x from editor and it gives me: 0.0423

Then i checked object3 position x from editor and it gives me :  0

I think below function does not realize it correctly.

object3->setWorldRotation(Object2->getWorldRotation()); 

So how can i set object3 position to object2 position?

Link to comment

Thank you so much for your help.I solved it with the function you specified(setworldposition and setworldtransform).But i have another problem.

I couldn't remove object2 with

Editor::get()->removeNode(object2);

Basically , object3 acts the same as object2. The same objects behave as if they were.So , when I disable object2, object3 closes.

I didn't understand why they act like a same object.

Link to comment
×
×
  • Create New...