Version: 2019.4
LanguageEnglish
  • C#

AssetPostprocessor.OnPreprocessMaterialDescription(MaterialDescription,Material, AnimationClip[])

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Parameters

description MaterialDescription structure describing the imported material properties and animations.
material The material generated by the Model Importer.
animations The animation clips generated by the Model Importer.

Description

Add this function to a subclass to recieve a notification when a material is imported from a Model Importer.

This function is only called when ModelImporter.UseMaterialDescriptionPostprocessor is true. This function provides user control over material properties and animations during model import. The MaterialDescription structure contains all the material data read in the imported file which can be used to populate the material and animation clips in parameters.

using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEditor.AssetImporters;

public class CreateMaterialFromMaterialDescription : AssetPostprocessor { 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); } } }