Documentation

Unity Engine

Unity Engine

OnPreprocessMaterialDescription(MaterialDescription, Material, AnimationClip[])

Add this function to a subclass to recieve a notification when a new material is created during the import of a ModelImporter.
Read time 1 minuteLast updated 4 hours ago

Definition

OnPreprocessMaterialDescription()

public void OnPreprocessMaterialDescription(MaterialDescription description, Material material, AnimationClip[] animations)

Parameters

A MaterialDescription that describes the imported camera properties and animations.

material

The material generated by the Model Importer.

animations

AnimationClip[]
The animation clips generated by the Model Importer.

Remarks

Unity only calls this function if you set ModelImporter.materialImportMode to ModelImporterMaterialImportMode.ImportViaMaterialDescription. This function gives you control over material properties and animations during the model import process. The MaterialDescription structure contains all the material data from the imported file. You can use it to populate the material and animation clips.

Examples

using System.Collections.Generic;using UnityEditor;using UnityEngine;using UnityEditor.AssetImporters;public class CreateMaterialFromMaterialDescription : AssetPostprocessor{ // Increment the version number, when the AssetPostprocessors code/behavior is changed static readonly uint k_Version = 0; public override uint GetVersion() { return k_Version; } public void OnPreprocessMaterialDescription(MaterialDescription description, Material material, AnimationClip[] materialAnimation) { var shader = Shader.Find("Standard"); if (shader == null) return; material.shader = shader; List<string> props = new List<string>(); // list the properties of type Vector4 : description.GetVector4PropertyNames(props); Debug.Log(props); // Read a texture property from the material description. TexturePropertyDescription textureProperty; if (description.TryGetProperty("DiffuseColor", out textureProperty)) { // Assign the texture to the material. material.SetTexture("_MainTex", textureProperty.texture); } }}