Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add MirrorRenderPipelineConverter for URP Compatibility #3994

Merged
merged 3 commits into from
Mar 6, 2025

Conversation

MrGadget1024
Copy link
Collaborator

image

Overview

This pull request introduces MirrorRenderPipelineConverter, an editor script that automatically converts materials in the Assets/Mirror/Examples folder from Unity’s built-in render pipeline (e.g., Standard, Legacy Shaders) to the Universal Render Pipeline (URP) in Unity 6000+. It ensures Mirror Networking’s example scenes remain visually consistent and functional in modern URP projects, addressing the shift from the default built-in pipeline (Unity 2019) to URP in Unity 6000.

Key Features

  • Automatic Conversion: Runs on project load, detects URP, and prompts with options: “Go Ahead” (convert), “Not Now” (skip), or “Don’t Ask Again” (set flag without converting).
  • Targeted Scope: Only processes .mat files within Assets/Mirror/Examples and subfolders, preserving user project assets.
  • Property Preservation: Transfers critical material properties:
    • Albedo color (_Color to _BaseColor)
    • Texture and tiling (_MainTex to _BaseMap, including _MainTex_ST)
    • Normal maps (_BumpMap)
    • Metallic and smoothness (_Metallic, _Glossiness to _Smoothness)
    • Transparency (render queue to _Surface)
    • Forward rendering options (_SpecularHighlights, _GlossyReflections to _EnvironmentReflections)
  • Shader Handling: Forces conversion of incompatible shaders (Standard, Legacy Shaders/*) to URP/Lit, skips URP-compatible shaders (e.g., Skybox/6 Sided).
  • Debugging Support: Extensive logging with clickable material references in the Console.

Motivation

Starting with Unity 6000, the built-in render pipeline is optional, and URP is the default. Without conversion, Mirror’s example materials (built for Unity 2019’s built-in pipeline) appear pink or incorrect in URP projects due to shader incompatibility. This script eliminates manual updates, ensuring a seamless experience for users upgrading to Unity 6000+.

Implementation Details

  • Trigger: Uses [InitializeOnLoad] to check on project open, with a flag file (MirrorExamplesPipelineConverted.txt) to prevent re-prompting.
  • Path Detection: Dynamically finds the Examples folder relative to the script’s location, accommodating user folder rearrangements.
  • Robustness: Wraps conversion in a try-catch block, filters for .mat files, and validates shader availability.
  • User Choice: Dialog respects user intent, with button order adjusted for intuitive UX (Go Ahead = left, Don’t Ask Again = right, Not Now = middle).

Impact

  • User Experience: Examples work out of the box in URP, avoiding pink materials or manual fixes.
  • Maintainability: Clear comments and logs simplify future tweaks or debugging.
  • Compatibility: Supports Unity 6000+ URP projects while respecting built-in pipeline users.

Testing

  • Validated in a fresh Unity 6000 URP 3D project with iterative imports:
    • Confirmed preservation of color, texture, tiling, transparency, and rendering options (e.g., Ground.mat, Robot_Color, Portal).
    • Verified settings like shininess by matching original _GlossyReflections and _SpecularHighlights settings.
  • Logs provide material-specific feedback for verification.

@MrGadget1024 MrGadget1024 added enhancement New feature or request Awaiting Review labels Mar 1, 2025
@MrGadget1024 MrGadget1024 requested a review from miwarnec March 1, 2025 17:49
@miwarnec miwarnec merged commit 5ce4144 into master Mar 6, 2025
8 checks passed
@miwarnec miwarnec deleted the URPConverter branch March 6, 2025 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Review enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants