docs.unity3d.com
Search Results for

    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)
        {
        }
    }
    
    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)