Change the color of one of several 3D models(unity-chan)

[Assumption]

I’m preparing a player unity-chan and a non-player unity-chan in the same scene, and I’m trying to change only the color of the non-player unity-chan (trying to make it white or semi-transparent).

[Problem/error message]

When I try to change (reset) a material or shader in unitychan/meshroot from the hierarchy using inspector, the change is also applied to the original data in Assets or to the player unitychan in the same scene.


I tried Unpack and other methods to see if it had something to do with the Prefab, but it didn’t work. I know this may be a bit of a detail, but I’d appreciate it if you could enlighten me on the order of operations.

Apart from the root cause, if there is a better way to change the color of 3D models like unity-chan, we would like to hear about it as well.

materials are shared. whatever change you make on a material is global. if you want to change a specific model’s material color you need to create another material (or material variant)

A new feature was added in Unity 2022.1 for Material Variants. Read more about it here: https://blog.unity.com/engine-platform/material-variants-the-solution-for-managing-complex-material-libraries and here https://docs.unity3d.com/Manual/materialvariant-concept.html

This allows you to have an inherited copy of the base material where you can make changes that don’t affect the original, but it still updates when the original was changed. hope that helps!

Well maybe if you can fix this error you can use it , sorry :slight_smile:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ChangeColor : MonoBehaviour
{
    [SerializeField] private Color changedColor;
    [SerializeField] private GameObject[] cubes;
    private GameObject SelectedObject;
    
    private void Update()
    {
        if(Input.GetKeyDown(KeyCode.C))
        {
            ChangeRandomColor();
        }
    }

    private void ChangeRandomColor()
    {
        SelectedObject = cubes[Random.Range(0, 6)];
        SelectedObject.GetComponent<Renderer>().material.color = changedColor;
    }
}