unity runtime_error ai_generated true

InvalidOperationException: ParticleSystem.CustomDataModule.SetVector: custom data index 1 is out of range (max 2)

ID: unity/particle-system-culling-error

Also available as: JSON · Markdown · 中文
92%Fix Rate
88%Confidence
1Evidence
2023-06-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
2022.3.5f1 active
2023.1.2f1 active
2021.3.25f1 active

Root Cause

Attempting to access a custom data stream index that exceeds the enabled count in the ParticleSystem's CustomDataModule.

generic

中文

尝试访问的自定义数据流索引超过了ParticleSystem的CustomDataModule中启用的数量。

Official Documentation

https://docs.unity3d.com/ScriptReference/ParticleSystem.CustomDataModule.html

Workarounds

  1. 95% success In Inspector, select ParticleSystem, expand CustomDataModule, ensure 'Custom1' and 'Custom2' are enabled (checkboxes). In script, use GetCustomDataModule to verify enabled streams: var cdm = ps.customData; if (cdm.enabled && cdm.GetMode(ParticleSystemCustomData.Custom1) != ParticleSystemCustomDataMode.Disabled) { cdm.SetVector(ParticleSystemCustomData.Custom1, 0, vec); }
    In Inspector, select ParticleSystem, expand CustomDataModule, ensure 'Custom1' and 'Custom2' are enabled (checkboxes). In script, use GetCustomDataModule to verify enabled streams: var cdm = ps.customData; if (cdm.enabled && cdm.GetMode(ParticleSystemCustomData.Custom1) != ParticleSystemCustomDataMode.Disabled) { cdm.SetVector(ParticleSystemCustomData.Custom1, 0, vec); }
  2. 85% success Set custom data index to 0 (first stream) if only one stream is needed: cdm.SetVector(ParticleSystemCustomData.Custom1, 0, vector);
    Set custom data index to 0 (first stream) if only one stream is needed: cdm.SetVector(ParticleSystemCustomData.Custom1, 0, vector);

中文步骤

  1. In Inspector, select ParticleSystem, expand CustomDataModule, ensure 'Custom1' and 'Custom2' are enabled (checkboxes). In script, use GetCustomDataModule to verify enabled streams: var cdm = ps.customData; if (cdm.enabled && cdm.GetMode(ParticleSystemCustomData.Custom1) != ParticleSystemCustomDataMode.Disabled) { cdm.SetVector(ParticleSystemCustomData.Custom1, 0, vec); }
  2. Set custom data index to 0 (first stream) if only one stream is needed: cdm.SetVector(ParticleSystemCustomData.Custom1, 0, vector);

Dead Ends

Common approaches that don't work:

  1. Increasing the index value in code 90% fail

    The error is about index out of range; increasing index makes it worse.

  2. Disabling CustomDataModule entirely 50% fail

    Removes custom data functionality but may break intended effects.