{"record":{"id":"745f9cb1bf8139e6","repo":"BabylonJS/Babylon.js","slug":"initial-color-gradient-values-not-found-in-context","errorCode":null,"errorMessage":"Initial color gradient values not found in context.","messagePattern":"Initial color gradient values not found in context\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Particles/Node/nodeParticleSystemSet.helper.ts","lineNumber":518,"sourceCode":"    return updatedParticle;\r\n}\r\n\r\n/**\r\n * Creates the group of blocks that represent the particle color update\r\n * @param inputParticle The input particle to update\r\n * @param colorGradients The color gradients (if any)\r\n * @param context The context of the current conversion\r\n * @returns The output of the group of blocks that represent the particle color update\r\n */\r\nfunction _UpdateParticleColorBlockGroup(\r\n    inputParticle: NodeParticleConnectionPoint,\r\n    colorGradients: Nullable<Array<ColorGradient>>,\r\n    context: RuntimeConversionContext\r\n): NodeParticleConnectionPoint {\r\n    let colorCalculation: NodeParticleConnectionPoint | undefined;\r\n    if (colorGradients && colorGradients.length > 0) {\r\n        if (context.colorGradientValue0Output === undefined) {\r\n            throw new Error(\"Initial color gradient values not found in context.\");\r\n        }\r\n\r\n        context.ageToLifeTimeRatioBlockGroupOutput = _CreateAgeToLifeTimeRatioBlockGroup(context);\r\n        colorCalculation = _CreateGradientBlockGroup(context.ageToLifeTimeRatioBlockGroupOutput, colorGradients, ParticleRandomBlockLocks.OncePerParticle, \"Color\", [\r\n            context.colorGradientValue0Output,\r\n        ]);\r\n    } else {\r\n        colorCalculation = _BasicColorUpdateBlockGroup();\r\n    }\r\n\r\n    // Create the color update block clamping alpha >= 0\r\n    const colorUpdateBlock = new UpdateColorBlock(\"Color update\");\r\n    inputParticle.connectTo(colorUpdateBlock.particle);\r\n    _ClampUpdateColorAlpha(colorCalculation).connectTo(colorUpdateBlock.color);\r\n\r\n    return colorUpdateBlock.output;\r\n}\r\n\r","sourceCodeStart":500,"sourceCodeEnd":536,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Particles/Node/nodeParticleSystemSet.helper.ts#L500-L536","documentation":"When converting a legacy particle system to a Node Particle System, the helper builds a gradient-based color computation for particles that have color gradients over their lifetime. It requires a prior block group that computes the gradient's endpoint value at gradient index 0 to already exist in the shared RuntimeConversionContext. If that output slot is undefined, the conversion cannot wire the gradient inputs, so it throws instead of producing a broken graph.","triggerScenarios":"Calling _UpdateParticleColorBlockGroup (via the node-particle-system-set conversion of aParticleSystem with colorGradients) when context.colorGradientValue0Output is undefined — i.e. the initial color gradient value block group was never created during conversion of the particle system's constant/initial color properties.","commonSituations":"Converting a ParticleSystem whose color gradient setup skips the initial color step (e.g. a hand-built or hand-edited particle config, or a system variant whose constantColor/gradient0 setup path is not run), typically from serialization drift or a custom conversion entry point.","solutions":["Ensure the particle system being converted has its initial color gradient (index 0) value defined so the conversion creates colorGradientValue0Output before processing color gradients.","Update to a Babylon.js version where conversion of color gradients is fixed if your system data is valid but still triggers this.","As a workaround, remove or simplify colorGradients so the conversion path that requires the gradient-0 output is not taken, then rebuild the node graph manually."],"exampleFix":"// before: particle with colorGradients but no gradient[0] start value\nconst ps = new ParticleSystem(\"p\", 1000, scene);\nps.addColorGradient(0.5, new Color4(1, 0, 0, 1)); // no gradient at 0\n// after: define gradient at t=0 so the initial-value block group is created\nps.addColorGradient(0, new Color4(1, 1, 1, 1));\nps.addColorGradient(0.5, new Color4(1, 0, 0, 1));","handlingStrategy":"validation","validationCode":"// Ensure a gradient exists at t=0 before converting to node particles\nconst hasInitialGradient = ps.colorGradients?.some(g => g.gradient === 0);\nif (!hasInitialGradient) throw new Error(\"ParticleSystem needs a color gradient at 0 before node conversion\");","typeGuard":"function hasColorGradient0(ps: ParticleSystem): boolean {\n  return Array.isArray(ps.colorGradients) && ps.colorGradients.some(g => g.gradient === 0);\n}","tryCatchPattern":null,"preventionTips":["Always define color gradients starting at factor 0.","Avoid invoking node-system-set conversion helpers directly with a hand-built context.","Pin Babylon.js versions when serializing/converting particle systems across environments."],"tags":["node-particle-system","conversion","internal-state"],"backgroundTag":"missing-conversion-context-value","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}