Hello there !
I have been trying to implement a very simple AssetPostProcessor to force the collider type on Tile assets during import, depending on the path of the asset. We are starting to have hundreds of tiles and something like this would really help.
When I reimport my tile asset, the asset path is logged successfully but LoadAssetAtPath always returns null. I’ve been looking for solutions and alternatives for a while now but I really can’t figure out what’s is wrong in this code. Any tips ?
Edit : I’m on Unity 2019.4.10f1, this script is in an Editor assembly. I also tried LoadMainAssetAtPath and tried to log values in the assetImporter (name, userData are all empty…)
Thanks a lot
class TileAssetImporter : AssetPostprocessor
{
void OnPreprocessAsset()
{
if (assetPath.Contains("Collider_"))
{
Tile tile = AssetDatabase.LoadAssetAtPath<Tile>(assetPath);
Debug.Log(assetPath);
if (null != tile)
{
if (assetPath.Contains("None"))
{
tile.colliderType = Tile.ColliderType.None;
}
else if (assetPath.Contains("Sprite"))
{
tile.colliderType = Tile.ColliderType.Sprite;
}
else
{
tile.colliderType = Tile.ColliderType.Grid;
}
EditorUtility.SetDirty(tile);
AssetDatabase.SaveAssets();
}
else
{
Debug.LogError("Could not load Tile asset");
}
}
}
}