Jump to content

the problem with setEnable


photo

Recommended Posts

if bind a child node to a parent node, and the parent node setEnable(0), while the child node setParent to another parent node(have setEnable(1)), the child node will not be seen.

 

here is some code

 

 

 

NodeDummy mNodeDummy ;

 

/// set child node to another parent node

void callback_redirector()

{

/// another parent node

Node testMesh = engine.editor.getNodeByName( "testMesh" ) ;

 

mNodeDummy.setEnabled(1) ;/// this fuction is not worked

mNodeDummy.setParent(testMesh) ;

}

 

void init()

{

/// create button and callback function(set child node to another parent node)

Gui gui = engine.getGui() ;

WidgetButton button = new WidgetButton(gui,"setParent");

WidgetWindow window = new WidgetWindow(gui,"Window");

engine.gui.addChild(window, GUI_ALIGN_CENTER);

window.addChild(button,GUI_ALIGN_CENTER);

button.setCallback(GUI_CLICKED,"callback_redirector");

 

/// create particle

ObjectParticles mObjectParticles = new ObjectParticles();

mObjectParticles.setName("NewParticles") ;

mObjectParticles.setEnabled(1) ;

mObjectParticles.setEmitterEnabled(1) ;

mObjectParticles.setSpawnRate(100) ;

mObjectParticles.setParticlesType(OBJECT_PARTICLES_TYPE_LENGTH) ;

mObjectParticles.setEmitterType(OBJECT_PARTICLES_EMITTER_SHIFT) ;

mObjectParticles.setVelocity(1,0) ;

mObjectParticles.setRadius(0.1,0) ;

mObjectParticles.setMaterial( "particles_base", 0 ) ;

 

/// create dummy node

mNodeDummy = new NodeDummy() ;

mNodeDummy.setEnabled(1) ;

mNodeDummy.setName("NewNodeDummy") ;

mObjectParticles.setParent(mNodeDummy) ;

 

/// parent node

Node testBox = engine.editor.getNodeByName( "testBox" ) ;

mNodeDummy.setParent(testBox) ;

/// set parent node does not enable

testBox.setEnabled(0) ;

}

Link to comment

the child node will not be seen.

 

What do you expect to see ? Your immediate child node is a NodeDummy, which itself is always invisible. Your ObjectParticles child of child has a SHIFT emitter, so particles will only be spawned/visible if you move your node hierachy. Is this the case ?

Link to comment

What do you expect to see ? Your immediate child node is a NodeDummy, which itself is always invisible. Your ObjectParticles child of child has a SHIFT emitter, so particles will only be spawned/visible if you move your node hierachy. Is this the case ?

 

NodeDummy child move in update function, if you suspected, you will set the emitter type of ObjectParticles child to point, or set ObjectParticle to target parent node immediately.

Link to comment

and...

set child node to another parent node, that is executived immediately, will not happend that case.So you will better create a callback function to set child node to another parent node, and click the button.

Link to comment

That's an emergency, I Need to set Particle between several parents, and the parent will be setEnable(0) sometimes.

How to solve this question.Please answer me.

Link to comment

Provide smallest possible working test case (zipped *.cpp,*.world and required resources e.g. textures) for reproduction of problem. Otherwise in most cases it's hard for others to provide help just based on problem description.

Link to comment

Provide smallest possible working test case (zipped *.cpp,*.world and required resources e.g. textures) for repoduction of problem. Otherwise in most cases it's hard for others to provide help just based on problem description.

 

here is a test case

test.rar

Link to comment

Good test-case ! Quick-fix is to call setEnabled() AFTER setParent() on particle system.

 

....
void callback_setParent()
{
   Node testBox1 = engine.editor.getNodeByName( "testBox1" ) ;
   Node testParticle = engine.editor.getNodeByName( "testParticle" ) ;

   testParticle.setParent(testBox1) ;
   testParticle.setEnabled(1) ;
}
....

 

This will enable the particle system attached on the new parent. Still there remains a problem, as re-enabling of particle system will also show 'old' emitted particles on previous parent until end of their lift time. I assume that this is not what you want.

 

Unfortunately currently there seems to be no way of clearing already emitted particles. A work-around could be to clone the particle system instead on re-assignment

 

....
void callback_setParent()
{
   Node testBox1 = engine.editor.getNodeByName( "testBox1" ) ;
   Node testParticle = engine.editor.getNodeByName( "testParticle" ) ;

   Node newParticle = testParticle.clone();

   engine.editor.addNode( newParticle );
   engine.editor.removeNode( testParticle );

   newParticle.setParent(testBox1) ;
   newParticle.setEnabled(1) ;
}

Link to comment

Good test-case ! Quick-fix is to call setEnabled() AFTER setParent() on particle system.

Great!! It worked.

 

This will enable the particle system attached on the new parent. Still there remains a problem, as re-enabling of particle system will also show 'old' emitted particles on previous parent until end of their lift time. I assume that this is not what you want.

 

Unfortunately currently there seems to be no way of clearing already emitted particles. A work-around could be to clone the particle system instead on re-assignment

I have modified the engine code(add clear function), so the particle emitter can clear the particles

Link to comment

Good test-case ! Quick-fix is to call setEnabled() AFTER setParent() on particle system.

Great!! It worked.

 

This will enable the particle system attached on the new parent. Still there remains a problem, as re-enabling of particle system will also show 'old' emitted particles on previous parent until end of their lift time. I assume that this is not what you want.

 

Unfortunately currently there seems to be no way of clearing already emitted particles. A work-around could be to clone the particle system instead on re-assignment

I have modified the engine code(add clear function), so the particle emitter can clear the particles

Link to comment

Good test-case ! Quick-fix is to call setEnabled() AFTER setParent() on particle system.

Great!! It worked.

 

This will enable the particle system attached on the new parent. Still there remains a problem, as re-enabling of particle system will also show 'old' emitted particles on previous parent until end of their lift time. I assume that this is not what you want.

 

Unfortunately currently there seems to be no way of clearing already emitted particles. A work-around could be to clone the particle system instead on re-assignment

I have modified the engine code(add clear function), so the particle emitter can clear the particles

Link to comment
×
×
  • Create New...