How does particle.velocity relate to the particle's actual velocity?

This question is about Shuriken particle systems. Based on my experiments it appears that the velocity property of a ParticleSystem.Particle object only reflects the constant Start Speed from the Main Particle System module, and does not account for any velocity changes from other modules. For example, here the start speed is set to 1:

101405-part-system-1.png

Also, the system includes a Velocity Over Lifetime setting like so:

101406-part-system-2.png

I use GetParticles() on the system in the Update() method and print the velocity, but the result is always just the velocity set by the Start Speed value, though I can clearly see the particles moving at different rates.

velocity=(0.0, 1.0, 0.0)
UnityEngine.MonoBehaviour:print(Object)

Is this the expected result? If so, is there any way to get the actual velocity for a given particle at any moment?

For other particle properties like size and color there are the GetCurrentSize() and GetCurrentColor() methods. Also, those properties are named startSize and startColor, making it clear that they are not necessarily the current value over the lifetime of the particle. I assumed that since velocity was simply called “velocity” and that since there is no GetCurrentVelocity(), that it contained the actual current value. But it appears this is not the case?

Thanks for your help!

Hi Malveka,

We store 2 types of velocity per particle:

  • persistent velocity

  • animated velocity

The persistent velocity persists across frames. eg the Force module applies a force, this gets applied to the velocity, and then that velocity is remembered between frames. Another great example of this is Start Velocity. It is applied once at the start, and remembered afterwards on each frame.

The animated velocity is used for non-physics effects (noise, velocity over lifetime, etc). This velocity is not remembered across frames, because these modules calculate a new velocity value each frame.

Unfortunately, the script only allows you to access the persistent velocity, and not the animated velocity. I will look at adding an accessor for this in a future version.

Until then, if you are using a JIT platform, you may be able to use Reflection to access this “secret” property. See c# - Find a private field with Reflection? - Stack Overflow

Something like:

var prop = particle.GetType().GetField("m_AnimatedVelocity", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
prop.SetValue(particle, "new value");

This will not work on AOT platforms (eg Consoles, or Android with Mono), but it will work on JIT platforms (eg PC)

Good luck!

Just very recently I have the same question and after few testing, Particle.velocity ignores (or its sum is calculated before) “velocity over lifetime”, “inherit current velocity” and “noise”. Other than these 3, “start speed”, “gravity modifier”, “limit velocity over lifetime”, “inherit initial velocity”, “force over lifetime” (randomized or not) and collision are all accounted to Particle.velocity. @Richardkettlewell or @karl_jones could shed some light, perhaps…

c.f. https://feedback.unity3d.com/suggestions/shuriken-particle-constantly-inherit-velocity-including-noise-of-sub-emitter-from-spawning-particle