unity runtime_error ai_generated true

无效操作异常:ParticleSystem.CustomDataModule.SetVector:自定义数据索引1超出范围(最大2)

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

ID: unity/particle-system-culling-error

其他格式: JSON · Markdown 中文 · English
92%修复率
88%置信度
1证据数
2023-06-20首次发现

版本兼容性

版本状态引入弃用备注
2022.3.5f1 active
2023.1.2f1 active
2021.3.25f1 active

根因分析

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

English

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

generic

官方文档

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

解决方案

  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);

无效尝试

常见但无效的做法:

  1. Increasing the index value in code 90% 失败

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

  2. Disabling CustomDataModule entirely 50% 失败

    Removes custom data functionality but may break intended effects.