Dragonfly Cloud announces new enterprise security features - learn more

Question: How do you convert materials to URP in Unity?

Answer

When working with Unity and upgrading a project to the Universal Render Pipeline (URP), you often need to convert the existing materials to make them compatible. Here are the steps to convert standard Unity materials to URP:

  1. Upgrade to URP: Before converting materials, ensure that your project is using URP.

    • Open Unity and go to Edit > Project Settings > Graphics.
    • Under Scriptable Render Pipeline Settings, click "Install UniversalRP Package" if URP is not already installed.
    • Once installed, create a URP asset by right-clicking in the Project window, then Create > Rendering > Universal Render Pipeline > Pipeline Asset.
    • Assign this asset to the Scriptable Render Pipeline Settings field.
  2. Converting Materials: With URP installed, you can now convert your materials.

    • Unity provides an automatic material upgrade tool accessible via Edit > Render Pipeline > Universal Render Pipeline > Upgrade Project Materials to UniversalRP Materials. This option will attempt to convert all materials in your project to be URP compatible.
    // Alternatively, you can use the following script to convert individual materials or perform batch conversion: using UnityEngine; using UnityEditor; using UnityEngine.Rendering.Universal; public class ConvertToURPMaterials { [MenuItem("Custom/Upgrade to URP Materials")] static void UpgradeMaterials() { // Ensure the user wants to perform the action if (!EditorUtility.DisplayDialog("Material Upgrade", "This will upgrade all materials to URP. It's recommended to back up your project first. Proceed?", "Yes", "No")) return; // Filter for all Material assets in the project string[] materialGUIDs = AssetDatabase.FindAssets("t:Material"); foreach (string guid in materialGUIDs) { string path = AssetDatabase.GUIDToAssetPath(guid); Material material = AssetDatabase.LoadAssetAtPath<Material>(path); if (material.shader.name.StartsWith("Standard")) // Check if material is using Standard shader { material.shader = Shader.Find("Universal Render Pipeline/Lit"); // Change to URP Lit shader Debug.Log($"Material {material.name} has been upgraded to URP Lit.", material); } // Add more conditions for other types of shaders if needed } Debug.Log($"All materials have been upgraded to URP."); } }
  3. Manual Conversion: If some materials don't convert properly, you may need to change them manually.

    • Open the material in the Inspector.
    • Click on the Shader dropdown menu and select a URP-compatible shader, such as "Universal Render Pipeline/Lit" for the standard shader or "Universal Render Pipeline/Unlit" for unlit shaders.
    • You may need to reassign textures and adjust settings since different shaders use different parameters.
  4. Checking for Issues: After converting, check your scene to ensure materials appear correctly. Look for any issues related to lighting, transparency, or texture mapping.

  5. Refine Your Materials: Finally, you may need to tweak your materials to take full advantage of URP’s features, like improved performance and rendering options.

By following these steps, you can successfully convert your materials to URP in Unity and continue developing your project with the benefits that the URP provides.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Switch & save up to 80% 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost