{"record":{"id":"d21c613d8ae82afd","repo":"Cysharp/UniTask","slug":"delay-does-not-allow-minus-delayframecount-delayf","errorCode":null,"errorMessage":"Delay does not allow minus delayFrameCount. delayFrameCount:","messagePattern":"Delay does not allow minus delayFrameCount\\. delayFrameCount:","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Delay.cs","lineNumber":141,"sourceCode":"        {\n            return UniTask.Yield(PlayerLoopTiming.LastFixedUpdate, cancellationToken, cancelImmediately);\n        }\n\n\t\tpublic static UniTask WaitForSeconds(float duration, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false)\n\t\t{\n\t\t\treturn Delay(Mathf.RoundToInt(1000 * duration), ignoreTimeScale, delayTiming, cancellationToken, cancelImmediately);\n\t\t}\n\n\t\tpublic static UniTask WaitForSeconds(int duration, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false)\n\t\t{\n\t\t\treturn Delay(1000 * duration, ignoreTimeScale, delayTiming, cancellationToken, cancelImmediately);\n\t\t}\n\n\t\tpublic static UniTask DelayFrame(int delayFrameCount, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false)\n        {\n            if (delayFrameCount < 0)\n            {\n                throw new ArgumentOutOfRangeException(\"Delay does not allow minus delayFrameCount. delayFrameCount:\" + delayFrameCount);\n            }\n\n            return new UniTask(DelayFramePromise.Create(delayFrameCount, delayTiming, cancellationToken, cancelImmediately, out var token), token);\n        }\n\n        public static UniTask Delay(int millisecondsDelay, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false)\n        {\n            var delayTimeSpan = TimeSpan.FromMilliseconds(millisecondsDelay);\n            return Delay(delayTimeSpan, ignoreTimeScale, delayTiming, cancellationToken, cancelImmediately);\n        }\n\n        public static UniTask Delay(TimeSpan delayTimeSpan, bool ignoreTimeScale = false, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false)\n        {\n            var delayType = ignoreTimeScale ? DelayType.UnscaledDeltaTime : DelayType.DeltaTime;\n            return Delay(delayTimeSpan, delayType, delayTiming, cancellationToken, cancelImmediately);\n        }\n\n        public static UniTask Delay(int millisecondsDelay, DelayType delayType, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false)","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/Cysharp/UniTask/blob/ceac8d6946b1125fe782cd171fbcb245b567dbf9/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Delay.cs#L123-L159","documentation":"Thrown by UniTask.DelayFrame when delayFrameCount is negative. UniTask frame-based delays use a counter that is decremented per frame; a negative starting value has no meaningful semantics. The guard catches accidental sign errors or uninitialized variables at the call site.","triggerScenarios":"Calling UniTask.DelayFrame(-1) or passing a computed frame count that underflows (e.g., subtracting a larger value from a smaller one).","commonSituations":"Arithmetic on frame counts without clamping, e.g., desiredFrames - extraFrames where extraFrames exceeds desiredFrames. Parameterizing delays via serialized fields in the Unity inspector with invalid defaults.","solutions":["Clamp the frame count to zero minimum: Math.Max(0, delayFrameCount)","Use UniTask.Yield() instead of DelayFrame(0) when you need a one-frame wait","Validate inspector-configured values in OnValidate or at startup"],"exampleFix":"// before\nawait UniTask.DelayFrame(myFrameCount); // throws if myFrameCount < 0\n\n// after\nawait UniTask.DelayFrame(Math.Max(0, myFrameCount));","handlingStrategy":"validation","validationCode":"int safeFrames = Math.Max(0, delayFrameCount);\nawait UniTask.DelayFrame(safeFrames);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp frame counts to zero minimum before passing to DelayFrame","Validate inspector-configured frame counts in OnValidate","Use UniTask.Yield() for zero-frame waits instead of DelayFrame(0)"],"tags":["unitask","delay","argument-validation","unity","csharp"],"backgroundTag":null,"analyzedSha":"ceac8d6946b1125fe782cd171fbcb245b567dbf9","analyzedAt":"2026-08-13T19:16:39.025Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}