Unity Water Pro material settings

Hello,

I have a project where I need multiple Water objects to appear through scripting.
I use the advanced Water4Example profided with Unity 3. I also update the settings of these water objects through scripting.

The problem is that through my scripting changing the values of one of the waters will also change the value in the other waters.
When I drag two water objects into the scene and start messing with the properties there it works fine.

If I create two Water objects through scripting however, they are somehow linked to the material. Changing a property in the Inspector will change the property on the material itself. Because of this both instances of the water objects will reflect the change.

Here is some code to show what I’m doing so far:

    // in Standard Assets\Water (Pro Only)\Water4\Sources\Scrips\WaterBase.cs
    private Material material;

    public void Awake(){
       material = (Material)Instantiate(Resources.Load("Water4Example"));
    }

    public Material GetMaterial(){
        return material;
    }

    // in my own code
    GameObject gameObject = (GameObject) GameObject.Instantiate(Resources.Load("Water4Example (Advanced)"), new Vector3(), new Quaternion());
    
    WaterBase base = gameObject.GetComponent< WaterBase>();
    SetValues(base.GetMaterial());       

    public void SetValues(Material mat){
        if (mat.HasProperty("_BaseColor")){
            refraction = mat.GetColor("_BaseColor");
        }
        ... etc etc for all the properties of the material
        
    }

I also changed the editor scripts of the water pro to handle my new material variable instead of the default sharedMaterial.
From what I can gather on the internet, instantiating the material is overkill because every object automatically has it’s own instance of a material? Can anyone verify this?
I also read that to change the material I should change the material value of the renderer property, but the water object doesn’t have one.

The fault might be that I directly change the values of the material associated with the waterbase script, but I don’t know of an other way to do this.

The problem, in short, is that when I instantiate an object in the way described above, changing one of the values of the objects will also change the value in the Water4Example material, and therefore in every other object that uses this material.

Can anyone help me?

Thanks in advance.

You need to make 2 materials in your project. Assign one material to your one water instance, and another material to your other water instance.

This will allow you to modify the material’s individually.

Thanks for your answer.

However, it didn’t work.
Even so, in theory I can have an arbitrary number of water objects so that is not a viable option.

When I create a new material in the script, using Instantiate(), the values in the inspector will be of the new material. The values used by the object to determine the waves however will still be the old material.

How can I change the material the water uses for renderering?

Thanks in advance