- Home /
Question by
PeterR · Feb 22, 2015 at 10:05 PM ·
c#unityeditor
Find Asset Path From Renderer Component
I am attempting to write an AssetPostprocessor script to make the type of material assigned to imported FBX files by default be "unlit/texture" instead of "Diffuse". It all works, except I cannot get AssetDatabase.GetAssetPath to return anything for me. It just returns an empty string.
I want to put the new material in the folder where the fbx was imported.
using UnityEngine;
using UnityEditor;
class MaterialImport : AssetPostprocessor
{
Material OnAssignMaterialModel(Material material, Renderer renderer)
{
material.shader = Shader.Find( "Unlit/Texture" );
string object_path = AssetDatabase.GetAssetPath(renderer.gameObject.GetInstanceID());
AssetDatabase.CreateAsset(material, object_path + renderer.gameObject.name + ".mat");
Debug.Log(object_path);
return material;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613184029im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
UI Buttons do not click 0 Answers
[CreateAssetMenu] For inherited ScriptableObjects 1 Answer
Navigate UI with gamepad 0 Answers