# InvalidOperationException: 不允许从构造函数创建 ScriptableObject

- **ID:** `unity/scriptableobject-constructor-called`
- **领域:** unity
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 93%

## 根因

在构造函数中使用了 'new' 关键字创建 ScriptableObject 实例，应使用 ScriptableObject.CreateInstance。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Unity 2022.3 | active | — | — |
| Unity 2023.1 | active | — | — |
| Unity 2023.2 | active | — | — |

## 解决方案

1. ```
   Replace 'new MyScriptableObject()' with 'ScriptableObject.CreateInstance<MyScriptableObject>()'.
   ```
2. ```
   If you need to initialize fields, create a static factory method that calls CreateInstance and then sets properties.
   ```

## 无效尝试

- **** — ScriptableObject must be created via CreateInstance, not by new, regardless of serialization attributes. (95% 失败率)
- **** — ScriptableObject requires explicit initialization via CreateInstance to set up internal Unity engine state. (85% 失败率)
