Skip to content

Conversation

@Scriptwonder
Copy link
Collaborator

@Scriptwonder Scriptwonder commented Dec 3, 2025

Previously it was shader assignment by request or iterative order from URP to Unlit, but LLM usually assign Standard in a URP setting.

This small fix introduce the helper to resolve some of the conflicts, while give warnings in the log to show if the user is creating a shader in a non-compatible setting.

Summary by CodeRabbit

  • New Features
    • Added centralized pipeline-aware shader resolution utility with automatic detection of Built-in, URP and HDRP pipelines and alias support.
  • Improvements
    • Switched material handling to use the centralized shader resolver.
    • Improved messaging for shader compatibility and pipeline mismatches.
    • Material property application now strips shader-only entries and applies remaining properties only when present.

✏️ Tip: You can customize this high-level summary in your review settings.

Previously it was shader assignment by request or iterative order from URP to Unlit, but LLM usually assign Standard in a URP setting.

This small fix introduce the helper to resolve some of the conflicts, while give warnings in the log to show if the user is creating a shader in a non-compatible setting.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 3, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds an internal RenderPipelineUtility to detect the active Unity render pipeline and resolve shaders (by name or alias) with pipeline-aware fallbacks and warnings; updates ManageAsset to use this utility and adjusts material property application accordingly.

Changes

Cohort / File(s) Summary
Shader Resolution Utility
MCPForUnity/Editor/Helpers/RenderPipelineUtility.cs, MCPForUnity/Editor/Helpers/RenderPipelineUtility.cs.meta
New internal static class providing pipeline detection (PipelineKind, GetActivePipeline), shader resolution (ResolveShader, ResolveDefaultLitShader, ResolveDefaultUnlitShader), alias resolution (ResolveAlias), candidate lookup (TryFindShader), and pipeline-mismatch warnings (WarnIfPipelineMismatch). Metadata asset added.
Material Management Integration
MCPForUnity/Editor/Tools/ManageAsset.cs
Replaced direct Shader.Find calls with RenderPipelineUtility.ResolveShader(...); improved error messaging about URP/HDRP compatibility; clone-and-strip behavior for material property payloads so shader is handled separately and remaining properties are applied only when present.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • New utility contains multiple resolver methods and fallback lists that should be validated.
  • Integration in ManageAsset.cs is limited but requires checking property cloning and conditional application.
  • Pay extra attention to:
    • correctness and completeness of shader name lists and aliases,
    • pipeline detection via GraphicsSettings.currentRenderPipeline,
    • warning semantics when resolved shader pipeline differs from active pipeline.

Possibly related PRs

Poem

🐰
I hop through pipelines, curious and bright,
Finding shaders by day and by night,
Alias or name, I sniff out the best,
Lit, unlit, or URP — I do the rest.
Hooray for tidy hunts and fewer nulls!

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title mentions a 'Temp Update on Material Assignment' but the changes primarily introduce a new RenderPipelineUtility for shader resolution and pipeline detection, with secondary updates to ManageAsset.cs. The word 'Temp' suggests this is temporary, which conflicts with introducing new utility infrastructure. Revise the title to reflect the main change, e.g., 'Add RenderPipelineUtility for pipeline-aware shader resolution' or 'Implement shader resolution with render pipeline support and warnings'.
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 221a14e and b4e8435.

📒 Files selected for processing (1)
  • MCPForUnity/Editor/Helpers/RenderPipelineUtility.cs (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Scriptwonder Scriptwonder changed the title Temp Update on Material Assignment [FIX] Temp Update on Material Assignment Dec 3, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
MCPForUnity/Editor/Helpers/RenderPipelineUtility.cs (1)

151-193: Consider using McpLog.Warn for consistency.

The warning logic is helpful, but lines 169, 173, 179, 183, and 189 use Debug.LogWarning directly while ResolveShader (line 69) uses McpLog.Warn. For consistency with the rest of the codebase (see MCPForUnity/Editor/Helpers/McpLog.cs), consider using McpLog.Warn throughout this class.

Apply this diff to use consistent logging:

                 case PipelineKind.HighDefinition:
                     if (shaderLooksUrp)
                     {
-                        Debug.LogWarning($"[RenderPipelineUtility] Active pipeline is HDRP but shader '{shaderName}' looks URP-based. Asset may appear incorrect.");
+                        McpLog.Warn($"Active pipeline is HDRP but shader '{shaderName}' looks URP-based. Asset may appear incorrect.");
                     }
                     else if (shaderLooksBuiltin && !shaderLooksHdrp)
                     {
-                        Debug.LogWarning($"[RenderPipelineUtility] Active pipeline is HDRP but shader '{shaderName}' looks Built-in. Consider using an HDRP shader for correct results.");
+                        McpLog.Warn($"Active pipeline is HDRP but shader '{shaderName}' looks Built-in. Consider using an HDRP shader for correct results.");
                     }
                     break;
                 case PipelineKind.Universal:
                     if (shaderLooksHdrp)
                     {
-                        Debug.LogWarning($"[RenderPipelineUtility] Active pipeline is URP but shader '{shaderName}' looks HDRP-based. Asset may appear incorrect.");
+                        McpLog.Warn($"Active pipeline is URP but shader '{shaderName}' looks HDRP-based. Asset may appear incorrect.");
                     }
                     else if (shaderLooksBuiltin && !shaderLooksUrp)
                     {
-                        Debug.LogWarning($"[RenderPipelineUtility] Active pipeline is URP but shader '{shaderName}' looks Built-in. Consider using a URP shader for correct results.");
+                        McpLog.Warn($"Active pipeline is URP but shader '{shaderName}' looks Built-in. Consider using a URP shader for correct results.");
                     }
                     break;
                 case PipelineKind.BuiltIn:
                     if (shaderLooksSrp)
                     {
-                        Debug.LogWarning($"[RenderPipelineUtility] Active pipeline is Built-in but shader '{shaderName}' targets URP/HDRP. Asset may not render as expected.");
+                        McpLog.Warn($"Active pipeline is Built-in but shader '{shaderName}' targets URP/HDRP. Asset may not render as expected.");
                     }
                     break;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 84f7b85 and 221a14e.

📒 Files selected for processing (3)
  • MCPForUnity/Editor/Helpers/RenderPipelineUtility.cs (1 hunks)
  • MCPForUnity/Editor/Helpers/RenderPipelineUtility.cs.meta (1 hunks)
  • MCPForUnity/Editor/Tools/ManageAsset.cs (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-10-13T13:27:23.040Z
Learnt from: msanatan
Repo: CoplayDev/unity-mcp PR: 316
File: TestProjects/UnityMCPTests/Assets/Tests/EditMode/Resources.meta:1-8
Timestamp: 2025-10-13T13:27:23.040Z
Learning: UnityMcpBridge is a legacy project kept for backwards compatibility; MCPForUnity is the only active Unity plugin project. GUID collisions between UnityMcpBridge and MCPForUnity are acceptable.

Applied to files:

  • MCPForUnity/Editor/Helpers/RenderPipelineUtility.cs.meta
  • MCPForUnity/Editor/Helpers/RenderPipelineUtility.cs
📚 Learning: 2025-09-03T16:00:55.839Z
Learnt from: dsarno
Repo: CoplayDev/unity-mcp PR: 0
File: :0-0
Timestamp: 2025-09-03T16:00:55.839Z
Learning: ComponentResolver in UnityMcpBridge/Editor/Tools/ManageGameObject.cs is a nested static class within ManageGameObject, not a sibling type. The `using static MCPForUnity.Editor.Tools.ManageGameObject;` import is required to access ComponentResolver methods directly without the outer class qualifier.

Applied to files:

  • MCPForUnity/Editor/Helpers/RenderPipelineUtility.cs
  • MCPForUnity/Editor/Tools/ManageAsset.cs
🧬 Code graph analysis (2)
MCPForUnity/Editor/Helpers/RenderPipelineUtility.cs (1)
MCPForUnity/Editor/Helpers/McpLog.cs (3)
  • McpLog (7-52)
  • Warn (43-46)
  • Debug (31-35)
MCPForUnity/Editor/Tools/ManageAsset.cs (1)
MCPForUnity/Editor/Helpers/RenderPipelineUtility.cs (6)
  • Shader (48-82)
  • Shader (84-93)
  • Shader (95-104)
  • Shader (106-136)
  • Shader (138-149)
  • RenderPipelineUtility (7-194)
🔇 Additional comments (11)
MCPForUnity/Editor/Helpers/RenderPipelineUtility.cs.meta (1)

1-11: LGTM!

Standard Unity metadata file with correct format and structure.

MCPForUnity/Editor/Tools/ManageAsset.cs (3)

199-202: LGTM! Good improvement to shader resolution.

The switch to RenderPipelineUtility.ResolveShader centralizes shader resolution logic and the improved error message provides helpful guidance about URP/HDRP installation or explicit shader paths.


206-218: LGTM! Well-structured property handling.

The logic correctly clones and strips the shader field to prevent duplicate shader assignment, and only applies remaining properties when present. This is good defensive programming.


908-917: LGTM! Consistent shader resolution in modify path.

The material modification flow now consistently uses RenderPipelineUtility.ResolveShader, aligning with the creation flow for centralized shader resolution.

MCPForUnity/Editor/Helpers/RenderPipelineUtility.cs (7)

7-15: LGTM! Clean utility class structure.

The internal static class with a clear PipelineKind enum provides good encapsulation for render pipeline detection and shader resolution.


17-22: LGTM! Comprehensive shader name coverage.

The shader name arrays provide good coverage of built-in, URP, and HDRP shaders with appropriate fallbacks for both lit and unlit variants.


24-46: LGTM! Solid pipeline detection logic.

The implementation correctly detects the active render pipeline using case-insensitive type name matching, with appropriate fallbacks for built-in and custom pipelines.


48-82: LGTM! Robust shader resolution with excellent fallback strategy.

The method implements a clear resolution precedence (alias → direct lookup → pipeline-specific defaults → built-in defaults) with appropriate warnings. The multi-level fallback ensures a shader is always returned.


84-104: LGTM! Pipeline-aware shader resolution with cross-pipeline fallbacks.

Both methods provide appropriate fallback chains, ensuring shaders can be found even when the expected pipeline shaders aren't available.


106-136: LGTM! User-friendly alias resolution.

The case-insensitive alias mapping provides intuitive names for common shader types, improving the developer experience when working with the API.


138-149: LGTM! Clean helper method.

The TryFindShader helper provides a convenient way to attempt multiple shader lookups with fallback, enhancing code readability throughout the utility.

@Scriptwonder Scriptwonder merged commit eb9327c into CoplayDev:main Dec 3, 2025
1 check was pending
@dsarno
Copy link
Collaborator

dsarno commented Dec 3, 2025

@Scriptwonder this is great and important. I was just thinking about tackling this yesterday. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants