Constant Rate | Visual Effect Graph | 10.2.2
docs.unity3d.com
    Show / Hide Table of Contents

    Constant Rate

    Menu Path : Spawn > Constant Rate

    The Constant Rate Block adds a spawn count over time at a constant rate. For instance, if the rate is 10, this block tiggers 10 spawn events per second for its Spawn Context. A rate below one is also valid, if the rate is 0.5, the rate is once every two seconds.

    Block compatibility

    This Block is compatible with the following Contexts:

    • Spawn

    Block properties

    Input Type Description
    Rate float The spawn rate per second.

    Remarks

    You can emulate this Block with the following equivalent custom spawner callback implementation:

    
    class ConstantRateEquivalent : VFXSpawnerCallbacks
    {
        public class InputProperties
        {
            [Min(0), Tooltip("Sets the number of particles to spawn per second.")]
            public float Rate = 10;
        }
    
        static private readonly int rateID = Shader.PropertyToID("Rate");
    
        public sealed override void OnPlay(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
        {
        }
    
        public sealed override void OnUpdate(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
        {
            if (state.playing)
            {
                float currentRate = vfxValues.GetFloat(rateID);
                state.spawnCount += currentRate * state.deltaTime;
            }
        }
    
        public sealed override void OnStop(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
        {
        }
    }
    
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023