Version: Unity 6.6 Alpha (6000.6)
LanguageEnglish
  • C#

AssetPostprocessor.OnAssignMaterialModel(Material,Renderer)

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

Parameter Description
material A temporary Material built from the assigned material in the renderer's Materials list. It is only valid during this callback and Unity destroys it afterward.
renderer The MeshRenderer or SkinnedMeshRenderer that will receive the Material.

Description

Override to choose which Material asset is assigned to an imported model renderer.

If null is returned, the default material assignment for the model is run.

The returned material must be an asset. Non-persistent Materials are rejected with an import error.

using UnityEngine;
using UnityEditor;

public class AssignSharedModelMaterial : AssetPostprocessor { public Material OnAssignMaterialModel(Material material, Renderer renderer) { // Use default assignment for this model. // return null;

// Assign an existing Material asset from the project (persistent). return AssetDatabase.LoadAssetAtPath<Material>("Assets/Materials/MyShared.mat"); } }