How to keep a child of a SceneNode when removing it?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
MickeyKnox
Posts: 58
Joined: Tue Apr 10, 2007 7:49 pm
Location: Karlsruhe

How to keep a child of a SceneNode when removing it?

Post by MickeyKnox »

A rocket in my game is a billboard with a ParticleSystem attached to it (as a child). When
i hit something, the billboard is removed, and so was the ParticleSystem, thus, the tail
the rocket produced vanished immediately. Now i want to keep the tail another second or so.

Well, i didn't succeded with that. The following code is inside my WeaponAnimator::animateNode
method and is executed, as soon as the rocket hits something:

Code: Select all

          // let the tail be another second
          for (core::list<scene::ISceneNode*>::ConstIterator iter = node->getChildren().begin();
               iter != node->getChildren().end(); iter++)
            if ((*iter)->getType() == scene::ESNT_PARTICLE_SYSTEM)
              {
                scene::IParticleSystemSceneNode* ps = static_cast<scene::IParticleSystemSceneNode*>(*iter);
                scene::ISceneNodeAnimator* ani = SceneManager->createDeleteAnimator(1000);
                ps->addAnimator(ani);
                ani->drop();
              }

          SceneManager->addToDeletionQueue(node);
          return;
The node is the one submitted with the call to WeaponAnimator::animateNode(ISceneNode* node, u32 time)
and is actually the billboard.
Sadly, the tail still vanishes immediatly. I tried to remove the ParticleSystem from the node,
but that only results in a segmentation fault.

Code: Select all

                scene::IParticleSystemSceneNode* ps = static_cast<scene::IParticleSystemSceneNode*>(*iter);
                scene::ISceneNodeAnimator* ani = SceneManager->createDeleteAnimator(1000);
                ps->addAnimator(ani);
                ani->drop();
                node->removeChild(ps);
Another approach was to grab the ParticleSystem, that a least does not lead to a segfault,
but still, the tail just vanishes immediately.

Code: Select all

                scene::IParticleSystemSceneNode* ps = static_cast<scene::IParticleSystemSceneNode*>(*iter);
                ps->grab();
                node->removeChild(ps);
                scene::ISceneNodeAnimator* ani = SceneManager->createDeleteAnimator(1000);
                ps->addAnimator(ani);
                ani->drop();
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Re: How to keep a child of a SceneNode when removing it?

Post by Acki »

I think you just need to remove the parent from the child:

Code: Select all

scene::IParticleSystemSceneNode* ps = static_cast<scene::IParticleSystemSceneNode*>(*iter);
ps->setPosition(ps->getAbsolutePosition());
ps->setParent(0);
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
MickeyKnox
Posts: 58
Joined: Tue Apr 10, 2007 7:49 pm
Location: Karlsruhe

Post by MickeyKnox »

That didn't help.
It just leads to another segfault, if i call ps->setParent(0) before adding the
DeleteAnimator. If i add the Animator first, i doesn't crash,
but the tail still vanishes immediately.

This looks all pretty strange to me...
Post Reply