Mounted particles killed
by Darkfire Games · in Torque Game Builder · 05/27/2008 (12:43 am) · 5 replies
When an enemy with particle object attached gets deleted the particle object goes as well, no surprise there.
As seen in this www.youtube.com/watch?v=89lADzGbx64 The end of the video best illustrates my problem.
How do i set it up such that the emitter gets killed but the already ejected particles live out their life until they die on their own terms :)
Probably a complete newbie question but i am still learning.
As seen in this www.youtube.com/watch?v=89lADzGbx64 The end of the video best illustrates my problem.
How do i set it up such that the emitter gets killed but the already ejected particles live out their life until they die on their own terms :)
Probably a complete newbie question but i am still learning.
About the author
#2
Let me tell you that I am absolutely amazed that this problem hasn't been noticed before. I'll search the forums and maybe post-up if someone has but a change was made early 2006 that broke this particle behaviour! Yes, 2006. Oh my gosh, people have not noticed that killing a particle-effect causes all particles to disappear immediately ... nasty. I hope I'm missing something. ;)
It's a simple change and I'll post the code change below in the hope that you do have the source.
Essentially, the call to the parent "safeDelete()" method shouldn't happen unless the effect is not playing. The particle effect manages this call internally as it may need to wait until all particles are dead until the safe-delete happens.
I have submitted this into the repo. A big thanks for reporting this one!
Melv.
05/28/2008 (3:42 am)
Thanks for the email. I found the reason why this isn't working and it's nothing to do with your scripts, it's actually an issue in the engine.Let me tell you that I am absolutely amazed that this problem hasn't been noticed before. I'll search the forums and maybe post-up if someone has but a change was made early 2006 that broke this particle behaviour! Yes, 2006. Oh my gosh, people have not noticed that killing a particle-effect causes all particles to disappear immediately ... nasty. I hope I'm missing something. ;)
It's a simple change and I'll post the code change below in the hope that you do have the source.
void t2dParticleEffect::safeDelete()
{
// Are we already waiting for delete?
if ( mWaitingForDelete )
// Yes, nothing to do!
return;
// Is effect playing?
if ( mEffectPlaying )
{
// Yes, so stop the effect and allow it to kill itself.
stopEffect(true, true);
}
// Call parent which will deal with the deletion.
Parent::safeDelete();
}... becomes...void t2dParticleEffect::safeDelete()
{
// Are we already waiting for delete?
if ( mWaitingForDelete )
// Yes, nothing to do!
return;
// Is effect playing?
if ( mEffectPlaying )
{
// Yes, so stop the effect and allow it to kill itself.
stopEffect(true, true);
}
else
{
// Call parent which will deal with the deletion.
Parent::safeDelete();
}
}Essentially, the call to the parent "safeDelete()" method shouldn't happen unless the effect is not playing. The particle effect manages this call internally as it may need to wait until all particles are dead until the safe-delete happens.
I have submitted this into the repo. A big thanks for reporting this one!
Melv.
#3
Guess ill just have to put up with it until a fix comes out. Many other things to tackle in the meantime.
05/28/2008 (5:17 am)
No problem, thanks for taking the time to have a look at the issue, but alas i do not have the source :(Guess ill just have to put up with it until a fix comes out. Many other things to tackle in the meantime.
#5
Is there TGB bug list to submit to? I find alot, and feel not entirely comfortable about posting them on the forum - as they may easily get lost again.
10/07/2011 (7:15 am)
Now all (at least INFINITE) effects are making it through clearScene(). I wonder if waiting for particles on object removed from the scene will ever end with something.Is there TGB bug list to submit to? I find alot, and feel not entirely comfortable about posting them on the forum - as they may easily get lost again.
Associate Melv May
When you mount the effect to the parent object you can specify whether the object being mounted to the parent is owned by the parent. This means that when the parent is deleted then any mounted object(s) will be deleted. You may already be doing this but it's an important point for the next bit.
When deleting a particle effect or to that matter any TGB object, use "safeDelete()" instead of the TorqueScript "delete()". This will only work on TGB objects like sprites, scrollers etc.
So on to the next bit; if you stop a particle effect with "stopEffect()" you'll notice two parameters. The first specifies whether the effect should wait until all currently emitted particles have died before actually flagging the effect as stopped. It will immediately stop new particles from being emitted. The second parameter states whether the effect should be killed when finally the effect is stopped.
What happens when a particle effect is "safeDeleted" is that internally a call to "stopEffect(true, true)" is called meaning that if you safeDelete a particle, it should wait until all its current emitted particles have died and will automatically delete itself when it has done so.
SafeDelete is called on child objects that are mount owned by a parent. What this means that in theory, if you mount an object (and mark it as owned which is an option of the mount call) then safeDeleting the parent should cause the child mounted particle effects to stop emitted, wait for currently emitted particles to die and then destroy the emitter object.
In summary, mount the effect with the "owned" flag and use "safeDelete" on the parent object.
If you're doing this then something is going wrong. If this is the case then (if possible) please send the scripts to "XXXX" and I'll see if I can figure out what's going wrong.
Although I wrote all this code I don't get to use it everyday so I may have forgotten something but I don't think so.
Melv.
EDIT: Email removed.