Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Material.CopyPropertiesFromMaterial

CopyPropertiesFromMaterial(mat: Material): void;
void CopyPropertiesFromMaterial(Material mat);
def CopyPropertiesFromMaterial(mat as Material) as void

Description

Copy properties from other material into this material.

	// Attach this to a gameObject that has a renderer.
	// Copies any property mat has and assigns it to this transform material

var mat : Material;

if (!mat) { Debug.LogError("Assign a material on the inspector."); return; }

renderer.material.CopyPropertiesFromMaterial(mat);

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public Material mat;
    void Example() {
        if (!mat) {
            Debug.LogError("Assign a material on the inspector.");
            return;
        }
        renderer.material.CopyPropertiesFromMaterial(mat);
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public mat as Material

	def Example() as void:
		if not mat:
			Debug.LogError('Assign a material on the inspector.')
			return
		renderer.material.CopyPropertiesFromMaterial(mat)