`urp-postprocessing`: Global Volume template's `profile.Add<T>()` overrides are lost after Editor restart (never added as sub-assets)

未关闭
#104 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
csharp, unity

调研方向

Read skills/urp-postprocessing/references/code-templates.md at “Creating a Global Volume with Effects” and the cited sections of skills/urp-postprocessing/SKILL.md. Check how the template adds components and how the skill describes persistence and diagnostics. Update the guidance and template to account for Editor asset persistence; done when newly added overrides survive an asset reload and the documented checks identify missing sub-assets.

由索引模型根据 Issue 内容生成。

描述

Plugin: 0.1.8-beta (main @ 3831ddb) · Unity: 6000.6.7f1 · URP / SRP Core: 17.6.0

Problem

skills/urp-postprocessing/references/code-templates.md, "Creating a Global Volume with Effects" (L19–43):

  1. AssetDatabase.CreateAsset(profile, …)
  2. profile.Add<Bloom>() / profile.Add<Tonemapping>()
  3. SetDirty(profile) + AssetDatabase.SaveAssets()

The added VolumeComponents are never stored as sub-assets of the profile. Everything looks right for the rest of the session, but after an Editor restart (or any reload of the asset) the profile has no overrides. We hit exactly this: a color-grading profile built this way came back empty after restarting the Editor.

SKILL.md L111, L141, L148, L156 present profile.Add<T>() as the way to add overrides, with no Editor-persistence caveat.

Why

  • VolumeProfile.Add(Type, bool) (com.unity.render-pipelines.core/Runtime/Volume/VolumeProfile.cs L109–123) only does CreateInstance(type) + components.Add(component) — no AssetDatabase.AddObjectToAsset, so the component lives in memory only and the reference does not survive serialization. On the next load VolumeProfile.OnEnable runs components.RemoveAll(x => x == null).
  • Unity's own Editor code always pairs Add with AddObjectToAsset: Editor/Volume/VolumeComponentListEditor.cs (inspector "Add Override", L518: AssetDatabase.AddObjectToAsset(component, asset)), Editor/Volume/VolumeProfileFactory.cs (VolumeProfileFactory.CreateVolumeComponent<T>, L109), Editor/Volume/VolumeProfileUtils.cs.

The skill's own checks don't catch it

  • SKILL.md L87–91 only warns when profile.components.Count == 0; in the same session the list still holds the in-memory instances, so it reports the setup as correct.
  • code-templates.md L123–125 says SaveAssets() persists the profile — true for editing existing overrides, not for newly added ones.

Suggested fix

  • In the template, after each Add<T>(): UnityEditor.AssetDatabase.AddObjectToAsset(bloom, profile); — or use UnityEditor.Rendering.VolumeProfileFactory.CreateVolumeComponent<T>(profile, overrides: true, saveAsset: false), then SaveAssets() once.
  • Key Facts: "On a profile asset in the Editor, Add<T>() alone is in-memory only; also call AssetDatabase.AddObjectToAsset. A runtime volume.profile instance doesn't need it."
  • Diagnostic: also warn when EditorUtility.IsPersistent(profile) and any component has !AssetDatabase.IsSubAsset(c).
主要语言
C#
星标
590
派生
67
平均合并
3 天 4 小时
30 天内合并 PR
13

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Unity-Technologies/unity-agent-plugin 的其他 Issue

查看 Unity-Technologies/unity-agent-plugin 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。