Hi, how do I slow down/stop the particles of a VFX graph programmatically? Just like pulling the “Rate” slider in the VFX Play Controls in the scene editor down to 1. Can I somehow access the Rate of the Play Controls or is there another way?
@skoteskote just the same way as you can control other parameters, but you have to do it from code. I’ll attach example in a moment.
// Remember to include this
using UnityEngine.Experimental.VFX;
public class AdjustParticleParams : MonoBehaviour
{
// Your visual effect gets assigned to this in UI (or do it in code)
public VisualEffect vfx;
[Range(0,1)] public float playRate;
void Start()
{
vfx = GetComponent<VisualEffect>();
}
void Update()
{
vfx.playRate = playRate;
}
}
If you want to control your own, arbitrary parameters you might have exposed in the Blackboard of the VFX Graph, you can do it this way:
public VisualEffect vfx;
public string exposedParameterName = "Spawn Rate";
[Range(0,1000)] public int spawnRate;
void Start()
{
vfx = GetComponent<VisualEffect>();
}
void Update()
{
vfx.SetUInt(exposedParameterName, (uint) spawnRate);
}
Expose it like this:
It should look like this in Inspector:
Then connect it to the Spawn node (well, it could be anything…)
4 Likes
@Olmi Awesome! Thank you so much for such an extensive reply.
It doesn’t work for me and I have the same setup as @Olmi (I can even see in the inspector the property value that changes, but the particles spawn at the same rate)