Pink Materials in Unity
Materials, Shaders, and Textures are used to render in Unity and they all have a close relationship in Unity.
Materials are descriptions of how a surface should be produced, containing texture references, tiling information, colour tints, and other details. The possibilities accessible to the material are determined by the shader it employs.
Shaders are short scripts that include the mathematical computations and methods used to calculate the colour of each displayed pixel based on the lighting input and material configuration.
Bitmap pictures are used to create textures. Material may contain texture references, allowing the Material’s shader to utilise the textures when computing an object’s surface colour.
Textures can indicate many different features of a material’s surface, such as reflectivity and roughness, in addition to the primary colour of an object’s surface.
A material uses a single shader, and the shader determines which options are accessible in the material. A shader expects to use one or more texture variables, and you can assign your texture assets to these texture variables using Unity’s Material Inspector.
The reason behind the pink materials in unity 3D is shaders mismatch or unsupported materials. It occurs when there is an application of different kinds of pipelines.
Render Pipelines
A render pipeline is a set of processes that takes the contents of a scene and renders them on the screen. These operations are, at a high level:
- Culling
- Rendering
- Post-processing
Different render pipelines have different capabilities and performance characteristics and are appropriate for various games, applications, and platforms.
Switching a project from one render pipeline to another might be problematic since different render pipelines use different shader outputs and may not have the same features. As a result, it’s critical to understand the various render pipelines that Unity offers. Therefore, it is recommended to select the best for the project early on.
Unity 3D Render Pipelines
- The Built-in Render Pipeline: Unity’s default render pipeline. It is a general-purpose render pipeline that has limited options for customization. Most of the assets available in unity are built using a built-in pipeline and are being used for a long time frame.
- The Universal Render Pipeline (URP): Scriptable Render Pipeline that is quick and easy to customise, and supports the creation of optimised graphics across a wide range of platforms.
- The High Definition Render Pipeline (HDRP): Scriptable Render Pipeline that allows the creation of cutting-edge, high-fidelity graphics on high-end platforms.
Pipelines and Default Shaders
- Built-in ====> Standard Shader
- URP ====> URP LIT Shader
- HDRP ====> HDRP LIT Shader
Only a few assets on the unity asset store are supported for the URP and HDRP pipeline as it has been introduced in recent times and due to the different nature of these pipelines. They have their default materials which are not interchangeable. Also, you can create your custom render pipeline using Unity’s Scriptable Render Pipeline API.
Let’s get started.
When you create a new unity project using unity hub, it prompts you to choose the template or render pipeline. For various types of Projects, Project Templates give pre-selected parameters based on established best practices. These options are optimised for 2D and 3D projects on all of Unity’s supported platforms. Here is the place where beginners make mistakes. 2D and 3D are the options for the default pipeline where you can choose either one according to your scene. But it recommends using the 3D extra template to avoid initial shade mismatch problems as it sets project parameters for Unity’s built-in renderer and post-processing functionality in 3D apps. The new post-processing stack, various Presets to jump-start work, and example content are all included in this project category.
(As per the image, 3D extra is not available for some of the versions.)
Other than 2D, 3D and 3D extra we have HDRP and URP. These two templates are to be used when you have a basic understanding of these. HDRP is used for high-end devices like PC and consoles. As the name is implicit, URP can be used for all kinds of platforms such as Mobile, PC and consoles with graphics.
Let’s get into our original problem and see how we can solve it.
Firstly, open a project using URP(It may take some time to create the project)
Edit > Project Settings > Graphics
Go to the Unity asset store (https://assetstore.unity.com/top-assets/top-free) and choose the asset to be opened in Unity 3D.
PS: You can notice that I have three assets in my store. I am going to use the “ARCADE: Free Racing Car” for the rest of the explanation.
Once the asset is opened in the package manager, make sure to download the assets and then import them.
Go to Project > Assets > ARCADE — Free Racing Car and load the “Day/Night”.
The below image shows how the loaded scene will look like. Here is the place where you experience the object in “PINK”.
Let us create a 3D Game Object and see the visualisation differences; The newly created object is displayed as expected. This is because the project has been created using URP and the game object has the same. That is, the below image clearly shows the selection of different shaders in two objects. This is called “Material Mismatch”.
In other words, if we remove the existing pipeline setting of the project, the material colour would be changed. For example, go to Edit > Project Settings > Graphics and change the pipeline setting from URP/LIT to “None”. Now you can witness that the “PINK” issue has been interchanged between the objects. Earlier “Cube” objects and the project have the URP/LIT as the shader. As they are matched, it displays the object properly. But when we change the project’s pipeline setting to “None”, it supports the standard shaders and is unsupported for URP/LIT.
Hope you have clearly understood that changing the entire project setting will not work when multiple objects have different shaders. Therefore, we need to change the shaders of the objects. For that, we need to undo the changes we have made in project settings. That is, change the pipeline settings to “URP/LIT”. This can be achieved using two methods,
Method 1: Select the materials/objects one by one and change the shaders value and then go to Project > Assets > Textures to restore the colours.
Method 2 : Go to Project > Assets > ARCADE — Free Racing Car > Materials. Here we need to select all the materials and then go to Edit > Render Pipeline > Universal Render Pipeline > and select either option. If you want to change the shader to all the project materials, then select “Upgrade Project Materials to UniversalRP Material” else choose “Upgrade Selected Materials to UniversalRP Material”. This will restore the textures as well.
Method 1 is not feasible in dealing with realtime projects as they may contain multiple objects. Changing the shaders and restoring the textures one by one will be an overhead to the development.
The same approach can be used to get rid of “PINK” objects when creating projects in HDRP.
Note: The texture restore option is applicable when changing the shaders from “Standard” to URP/HDRP. Therefore, when converting from different shaders, you need to restore the textures manually or change the existing shader to “Standard” and then use method 2 to change the shader and restore the texture.