Getting error message for destroyed bullets

// Error
ERROR:GAMESYS: Failed to setup state changed callback (has the calling script been destroyed?)

Has anyone dealt with such an error? This starts happening with the very first instance.

Code that executes on an collision

function on_message(self, message_id, message, sender)

	if message_id == hash("trigger_response") and message.enter then
		-- Hide the missle, disable collision, stop movement
		-- Explode animation		
		msg.post("#is_trigger", "disable")
		msg.post("#sprite", "disable")
		-- No more moving
		self.move.x = 0
		go.delete() -- Same result with and without this line
		
                -- Particle effect: Dirt explosion
		particlefx.play("#dirt_particles",
		function(self, id, emitter, state)
			if state == particlefx.EMITTER_STATE_SLEEPING then
				go.delete(".", true)
			end
		end)
		sound.play("main:/sfx_group#snowball")			
	end
end

it’s weird it’s like the script or the object gets deleted before calling that line i had this error i fixed it by creating another manager script and sending a message to it and he do the action but in your case the action is deleting the object so it should stay in the same game object you want to delete to try do detect the trigger from the other object and send a message to this object saying to him that he should delete and then delete the object and see if it works

Thank you. I will give it a try. I will report the results.

I am still learning Defold, so these are questions not suggestions…
One thing that strikes me as risky is having two go.delete calls (although you comment that it makes no difference). And am interested to know if it is OK to put go.delete in the call back.
Firstly when the delete occurs is a side effect of how long the particles take to play. Also how does the delete happen? I guess it is non blocking and a message gets sent off then the call back proceeds to complete at the same time; what happens if the GO is deleted first, does particlefx loose a memory reference or something?

Yes, it is ok to delete something in a callback. When you call go.delete() the object in question gets marked for deletion, but it lives on for the duration of the frame, and will be removed completely from the system before the next frame starts.

In general we always check if a reference is still valid before calling it. This is done in the engine, and it should be done by extension developers when using callbacks.

2 Likes