Particle end event like animation_done? (SOLVED)

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
3 Likes

Thank you! :hugs:

Can I use the technique written above? (ā€œEMITTER STATE_SLEEPINGā€) Particle end event like animation_done? (SOLVED)

I think it will work if you have only one emitter. Would be better to use this logic - itā€™s more universal.

1 Like

This is still an issue. In my game itā€™s not ideal to leave the game object deletion to the particle callback.

Is there a different workaround to avoid the "ERROR:GAMESYS: Could not run particlefx callback because the instance has been deleted." error? Removing the callback when the game object is deleted could work, but I donā€™t think thatā€™s possible now?

We should fix this. Can I please ask of you to create a small sample project and create a ticket for this issue and Iā€™ll promise to fix the check and stop spamming the console if the pfx has been deleted.

Deal! https://github.com/defold/defold/issues/5269

1 Like