Creating a particle effect from factory fails after first instance

I am creating a broken brick particle from a factory. I did this hoping that resources would be less instead of attaching the particle efx to each brick instance. Well, if I break a brick the particle plays correctly.

But if I break another brick immediately after, I get errors. The second ref to the factory is nil and subsequent calls fail.

See video / error message attached.

Attached is an error dump but with code that detects a nil ref.

DEBUG:SCRIPT: BREAK: 	url: [game:/instance445#brick_dark_brown]
ERROR:GAMESYS: ParticleFx could not be created since the buffer is full (256). Increase the 'particle_fx.max_count' value in [game.project](defold://open?path=/game.project)
ERROR:GAMEOBJECT: Could not spawn an instance of prototype /game/particlefx/brick_break.goc.
DEBUG:SCRIPT: SPAWN IS NIL
ERROR:GAMESYS: Failed to setup state changed callback (has the calling script been destroyed?)

Snip of basic settings per emitter.

Usually this kind of error can be fixed by increasing values in game.project file

1 Like

The particlefx.max_count value is the maximum number of particle fx components. Do you have that many components at the same time? It doesn’t seem right. Check the particle fx count using the profiler.

2 Likes

That is a good question. I forgot that my coins still have the particle effect attached to each instance and there are 203 coin instances and 8 collapsing bricks with attached particles live on the level.

My enemy “whack!” effect is not attached and is called dynamically. Let me delete some coins and see what happens.

Okay, delete a bunch of coins stopped the error, but now I am still getting this error for each broken brick.

DEBUG:SCRIPT: BREAK: 	url: [game:/instance324#brick_dark_brown]
DEBUG:SCRIPT: BREAK: 	url: [game:/instance65#brick_dark_brown]
ERROR:GAMESYS: Failed to setup state changed callback (has the calling script been destroyed?)

This is the source for the broken brick.

go.property("brick_set", hash("#brick_brown")) -- Default: changes during factory creation


----------------------------------
-- 
----------------------------------
function init(self)

	-- Create a url reference
	self.url = msg.url(nil, go.get_id(), self.brick_set)	
	print("BREAK: ", self.url)
end


----------------------------------
-- 
----------------------------------
function on_message(self, message_id, message, sender)

	if message_id == hash("playfx") and self.url then
		--print(self.url)
		particlefx.play(self.url,
		function(self, id, emitter, state)
			if state == particlefx.EMITTER_STATE_SLEEPING then
				go.delete(".", true)
			end
		end)
	end
end


----------------------------------
-- 
----------------------------------
function final(self)
	particlefx.stop(self.url, { clear = true })
	self.url = nil	
end

When you construct a URL using msg.url() you should not use a # symbol for the url fragment:

local good = msg.url("foo", "bar", "baz")
local bad = msg.url("foo", "bar", "#baz")

Not sure if it is the source of your problem but it is wrong at least.

1 Like

Okay. I think I figured it out. Thx.

Thanks for the on screen control module too! As you can see, I use it, though slightly modified for horizontal movement only. :slight_smile:

1 Like