Particle end event like animation_done? (SOLVED)

I want to destroy the particlefx and its game object when the particle finished playing. Right now I have to hard-coded the particlefx’s emitter’s duration in the script to destroy it when it ended.

Is there a way to be notified when the designated particle’s emitter (play_once) end or otherwise a way to get designated particle’s emitter’s duration from code.

It will be good because when designers changed the particlefx and also it’s duration the script just can handle it automatically instead of the designers have to let me know they changed and I have to change a variable duration that hard-coded in the script.

Thanks :smile:

2 Likes

Yes, this kind of functionality seems to be missing. @sicher, do you know if this has been discussed?

Particlefxs chaning is another use case for this :smile:

Not sure if it has been discussed but it seems like something useful.

I have created a feature request ticket: DEF-1546

2 Likes

Yea, method for getting emitter duration - cool idea.
Now I am using workaround with go.property with time before “death” and often I forget to change the value after particle changes.

The design part of this task has been completed a while back and it’s now awaiting implementation. Implementation in ticket DEF-1904

2 Likes

This has been implemented and released in version 1.2.88! Defold 1.2.88 has been released

1 Like

ERROR:GAMESYS: Could not run particlefx callback because the instance has been deleted.

how to remove particle with callback without error?

Oh, interesting! This sure sounds like a bug. @Andreas_Tadic?

1 Like

Forwarding this to @Johan_Beck-Noren

1 Like

Hello,

How are you using the particlefx when this occurs? Does it happen during the normal lifecycle of the particlefx or are you removing it mid-spawn for example?

1 Like

yes, removing when it’s playing. It’s a level restart I need to remove all level content immediately.

and one more question: how to stop particles immediately?
When I use particlefx.stop() - emitter to to spawn new particles, but old particles continue live some time.

What is the use case for this?

If I understand things correctly it might be better in your case to unload and load the entire collection, if you are restarting the level for instance.

If you really need to hide the spawned particles immediately you can try setting the emitted particle’s alpha to zero with something like:

particlefx.set_constant("#particlefx", "emitter", "tint", vmath.vector4(1,1,1,0))

In this example tint is defined in the default particlefx.material file.

/Johan

1 Like

ok, I made same workaround with size option.

what about my first question? Particle end event like animation_done? (SOLVED)

In my game restart of level just a recreating of game objects (go.delete_all and factory.create)
I have no sense reload whole collection.

OK cool :thumbsup:

Unfortunately there is no quick solution for not getting those error messages when you delete the particlefx instance. It has to do with how callbacks are designed in general in the engine. We are aware of the issue and we will plan it and hopefully look at it in the future.

All the best!

/Johan

1 Like

Any news on this? It’s really unfortunate that I cannot have something like a simple particle gameobject that is created with a factory when needed and removed when play is done.
It just spams the whole console with errors.

1 Like

It was implemented a couple of months ago, Teaser Fridays and Roadmap talks.

Oww…

3 Likes

unfortenatly it’s still an issue =(

UPD:
this issue only with particlefx.EMITTER STATE_POSTSPAWN but with particlefx.EMITTER STATE_SLEEPING it works fine.

local function particle_callback(self, particlefx_url, emitter_id, state)
  if state == particlefx.EMITTER_STATE_SLEEPING then
    go.delete(".")
  end
end

function init(self)
  particlefx.play(NAME, particle_callback)
end
3 Likes