AssetPostprocessor Help needed

Hello all,
i’m trying to put together script which should enable to automaticaly create materials on import with proper naming conversion… I’m good with that but i have few problems…

  1. it does not assign them to coresponding objects, just create them and correctly name
  2. it leaves standard [i think original import materials] on objects and in project view
  3. i’m not able to properly assign texture to coresponding material slot.

Resources:
Lightmaps are in Textures\LightMaps and have coresponding names vith suffix “_LightMap”

I’m mad from this so ANY help is good.

I’m quite new in this so do not throw stones after me :slight_smile:

CODE: mainly from Help

class MyMeshPostprocessor extends AssetPostprocessor {

	function OnAssignMaterialModel (material : Material, renderer : Renderer) : Material
	{
		var materialPath = "Assets/Materials/" + material.name + ".mat";
		var lightMap ;

		// Find if there is a material at the material path
		// Turn this off to always regeneration materials
		if (AssetDatabase.LoadAssetAtPath(materialPath)) 
		{
			material.shader = Shader.Find("Lightmapped/VertexLit");
			AssetDatabase.CreateAsset(material, "Assets/Materials/" + material.name + ".mat");
			lightMap = Resources.Load("Assets/Textures/LightMaps/" +material.name + "_LightMap");
			material.SetTexture("_LightMap", lightMap);
			AssetDatabase.AddObjectToAsset(lightMap, material);
			AssetDatabase.DeleteAsset ; //here i like to delete or update with new material, searching how to do it right way
			return material;
		}

	}
}

This throws after me this errors:

Assets/Editor/MyMeshPostprocessor.js(10,50): BCE0017: The best overload for the method 'UnityEditor.AssetDatabase.LoadAssetAtPath(String, System.Type)' is not compatible with the argument list '(String)'.
Assets/Editor/MyMeshPostprocessor.js(17,39): BCE0034: Expressions in statements must only be executed for their side-effects.

NoOne? :slight_smile: