Jump to content

clone() method help


photo

Recommended Posts

We're working on having a trail of dust (ObjectParticles), and wish to set up a node of ObjectParticles one time and then clone it as it's needed.

ObjectParticlesPtr sand_kick_actual = ObjectParticles::cast(Editor::get()->getNodeByName("ObjectParticles_0")->getNode()->clone());

sand_kick_actual->setEnabled(0);
sand_kick_actual->setRadius(0.01f, 0.01f);
sand_kick_actual->setWorldPosition(path_world_pos + random_offset);
sand_kick_actual->setEnabled(1);

However, at run-time this causes the following error message;

Assertion failed!

Program: ...ments\UNIGINE Projects\PBKC_2\bin\Unigine_x64d.dll
File: engine\world\WorldSpatial.cpp
Line: 2125

Expression: positions.find(position) != positions.end() && "WorldSpatial::removePosition(): can't find position"


 

How do you go about cloning particle systems (or nodes in general) ?

 

Link to comment

Hi,

the problem here, that Node::clone method returns an owner interface (NodePtr that is returned is owner of runtime node), but this NodePtr is a temporary variable, it delete runtime node after cast was done. So you need to get NodePtr itself, and than decide what to do with it's ownership.

NodePtr cloned_node = Editor::get()->getNodeByName("ObjectParticles_0")->getNode()->clone();
ObjectParticlesPtr sand_kick_actual = ObjectParticles::cast(cloned_node);

sand_kick_actual->setEnabled(0);
sand_kick_actual->setRadius(0.01f, 0.01f);
sand_kick_actual->setWorldPosition(path_world_pos + random_offset);
sand_kick_actual->setEnabled(1);

// if you don't want clone to be deleted on end of cloned_node scope, release it and pass to a new owner (other NodePtr or Editor ...)
cloned_node->release();

 

Link to comment
×
×
  • Create New...