Factory created collection w particleFX won't stop (SOLVED)

Here’s the set up:
Screen Shot 2023-06-29 at 7.38.23 AM

Here’s the script I use to stop the pfx:

function on_message(self, message_id, message, sender)
    if message_id == hash("Play") then
        particlefx.play("#pfx")
    elseif message_id == hash("Stop") then
        print('pfx stop')
        particlefx.stop("#pfx", { clear = true })
    end
end

Here’s how I message the script:

    msg.post(soul.collection[hash("/soulPFX")], "Stop")

When I send the message, I get the printed string, but the pfx just keeps on particle-ing.
No errors are given. But I think it’s an addressing problem.

What if you try an empty project with a single pfx which you start in init() and then stop on a timer or on mouse click? Does it stop as expected?

Can you isolate your project to a small project that you can share?

Ack! I knew you were going to ask that! : - )

If only I could ask an AI to write that code… (give me a few days to figure it out) double :grin:

Hopefully I can cobble it together tomorrow. Thanks for replying!

Here’s a project that repeats my problem. I’m running on OSX 10.14.6

pfx stop test.zip (4.4 MB)

Run the project and press the spacebar to send the stop message. You should see ‘pfx stop’ printed from the particle script, just before the .stop call.

1 Like

I don’t think you shared exactly what you were testing yourself. The project will not build in the state you shared it (there are a bunch of missing resources).

Still, I took a look and the particlefx_play.script looks like this:

function init(self)
	particlefx.play(".")
end

function on_message(self, message_id, message, sender)
    if message_id == hash("Play") then
        particlefx.play("#explosion")
    elseif message_id == hash("Stop") then
        print('pfx stop')
        particlefx.stop("#explosion", { clear = true })
    end
end

I was not able to find a single place where a “Stop” message was sent to that script. And no “Play” message either.

Something to note is that you do a particlefx.play(".") in init() of this script. This will start playing one instance of the particlefx animation. If I then add a call to particlefx.stop("#explosion") the pfx will indeed not stop. I believe it has to do with the “.” vs “#explosion”. You should play “#explosion” and stop “#explosion”.

3 Likes

The space bar handling code is in the camera script. But I will check out ‘Play’ in my main project. Thank you.

1 Like

Hi there - @britzl is right, the line in init( ) is the problem.
Having removed the missing resources, the test project works and you can stop the animation. If you add a key for playing and the “Play” message, playing the animation works too.

function init(self)
    -- particlefx.play(".")
    particlefx.play("#explosion_1")
end

function on_message(self, message_id, message, sender)
    if message_id == hash("Play") then
        particlefx.play("#explosion_1")
    elseif message_id == hash("Stop") then
        print('pfx stop')
        particlefx.stop("#explosion_1", { clear = true })
    end
end
2 Likes

The documentation for

particlefx.stop

should be updated to say that it only works after a play call has been made to the specific thing that is being stopped.

Personally, I think the stop implementation should handle however a pfx started.

I think I agree with you, although I don’t know the details of the implementation so I can’t say how hard or easy it would be. Please create a ticket on GitHub for this request!