Jump to content

[SOLVED] nodeReference downcast


photo

Recommended Posts

Posted

   {

   NodeReferencePtr node_ref = NodeReference::create(NodeRef);              // NodeRef is file parameter (.node)
    node_ref->setName("NodeReference_0");
    
    node_ref->release();
    Editor::get()->addNode(node_ref->getNode());

   NodePtr  node = Editor::get()->getNodeByName("NodeReference_0");
    ObjectMeshStaticPtr node1 = ObjectMeshStatic::cast(node);                           //return null
    ObjectMeshStaticPtr node2 = ObjectMeshStatic::cast(node);                           //return null

}

NodeRef is material_ball.node(material_ball's nodeReference).

 

material_ball's Original type is  ObjectMeshStatic. So I thought that I can cast to ObjectMeshStatic. but That casting return null.

How do I cast to ObjectMeshStatic?

Posted

Hi dongju.jeong,

You cannot downcast the node to ObjectMeshStatic this way, as it's original type is NodeReference, not ObjectMeshStatic. Guess in your case you should use the NodeReference::getReference() method (follow the link to see the related code-snippet in the doc).

Hope this helps!

Thank you!

Posted (edited)

Ok,  that link have something wrong ( 404 forbidden).

 

but I understand getReference() function. and  I get a workaround. 

              ObjectMeshStaticPtr node1 = ObjectMeshStatic::cast(NodeReference::cast(node)->getReference());

Thank you

 

If I editing node1 for something related to the ObjectMeshStatic class, would it apply to the node (NodeReference)?

Edited by dongju.jeong
  • silent changed the title to [SOLVED] nodeReference downcast
×
×
  • Create New...