Particlefxs chaning is another use case for this
Not sure if it has been discussed but it seems like something useful.
I have created a feature request ticket: DEF-1546
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
ERROR:GAMESYS: Could not run particlefx callback because the instance has been deleted.
how to remove particle with callback without error?
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?
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
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
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
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.
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
I get an error when deleting an object containing an emitter.
I use an example from here: https://www.defold.com/ref/particlefx/#particlefx.play:url--emitter_state_function-
I add code: go.delete()
if emitter == hash("emitter") and state == particlefx.EMITTER_STATE_POSTSPAWN then
-- emitter is done spawning particles...
go.delete()
end
And I get it in the console:
ERROR:GAMESYS: Could not run particlefx callback because the instance has been deleted.
When will this error be fixed?
Do I need to create a separate topic to discuss the problem?
You receive this error because you remove particle before it receives all the messages.
I am using the next code for removing particlefx:
go.property("path", msg.url("#particle_fx"))
go.property("need_to_remove", 1)
local function particle_callback(self, particlefx_url, emitter_id, state)
if state == particlefx.EMITTER_STATE_PRESPAWN then
self.counter = self.counter + 1 -- count how many emitters start working
elseif state == particlefx.EMITTER_STATE_SLEEPING then
self.counter = self.counter - 1 -- when the last emitter is sleeping remove GO
if self.counter == 0 then
go.delete(".")
end
end
end
function init(self)
self.counter = 0
if self.need_to_remove == 1 then
particlefx.play(self.path, particle_callback)
else
particlefx.play(self.path)
end
end