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.
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.
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?
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.
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:
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.
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.
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