Is it possible to play a PKFX in Unity from any given Deterministic point in time? And Replay it?

0 like 0 dislike
I'm on a project that is considering using Popcorn in Unity.  However our game needs to be able to replay effects.

There will be times that I need to simulate Popcornfx Assets slowly so that in our spectactor mode you can quickly time scrub.  For example after an effect has played we would like to be able to jump to frame 8 of a simulation.

Is this possible with the current state of the plugin?  If so.  How do I do this?
asked Jun 8 by Kris Orpilla

1 Answer

0 like 0 dislike
Hi Kris,

There are a number of hacks you can use in the C++ SDK, but there's no real satisfactory "scrubbing" solution that doesn't require either re-simulating the whole effect up to the point you're scrubbing, or saving the particle state each frame.
On the Unity plugin side, I don't believe any of that is exposed unfortunately.

There are ways to make some effects "scrubbable" by totally changing the way they are made and the logic behind, but if you want this for most or all of your effects, it doesn't seem like a realistic option.

The way to make an effect scrubbable is basically changing the way time is taken into account (and disabling everything that's not scrubbable by nature, such as collisions).
So for example, you'd create an "EffectAge" attribute, and compute each particle's age based on the age of its spawner or the value of "EffectAge" when it was spawned. Then for an effect using velocity and acceleration, would have to re-make a physics evolver that evaluates the position from a starting position and velocity and the particle age (and basically make all the evolvers a function of the particle age instead of dt or scene.Time (LifeRatio is ok as you can recompute it easily from the age).
Then you'd also need to handle the case when "EffectAge" gets scrubbed _before_ the particle birth, and keep that particle alive but "hide" it (setting size and color to 0 is a good option)
you'll also need some special management on the C# side of the unity plugin, so that when you're scrubbing back and forth, it doesn't update the spawners with a nonzero timestep (although calling Update(0.0) will skip the updates, so you'd need to hack it by passing it a very small dt such as 0.000001 so that it doesn't skip the update BUT still doesn't advance significantly the regular spawners, which would continue giving birth to new particles as they wouldn't have knowledge of that "EffectAge" attribute)
If you really need to go down that route drop us a mail at support.

yeah it sounds like a pain, and it is, we still have to find a clean and efficient way of doing this that hopefully works with all the crazy stuff you can make with popcorn scripts and doesn't have a 10-foot-long list of features you musn't use if you want it to work.

My hope is that v2 will allow openings of pathways that could lead to an elegant solution for this, either through the creation of a bunch of smart templates that hide the complexity I mentioned above and that you can reuse in all your effects, or through a more "builtin" solution using all the graph analysis we can do on the v2.0 nodegraphs, where we have much more information compared to v1, and can deduce/transform things at a much higher level.
answered Jun 25 by Julien (29,120 points)