Unity解决:报错requires the mesh to be marked as readable in order to be usable with the given transform

运行或者打包时候报错:This MeshCollider requires the mesh to be marked as readable in order to be usable with the given transform.

解决方法:开启Meshes的读写

 可以写一个批量处理的脚本:

using UnityEngine;
using UnityEditor;
using System.IO;
 
public class FixModel
{
    [MenuItem("Tools/FixModel")]
    static void Fix()
    {
        var fs = Directory.GetFiles(Application.dataPath, "*.FBX", SearchOption.AllDirectories);
        foreach(var f in fs)
        {
            var path = f.Replace(Application.dataPath, "Assets");
            var imp = AssetImporter.GetAtPath(path) as ModelImporter;
            if(null == imp)
            {
                Debug.LogError(Path.GetFileName(f) + " is not a Model");
            }
            else
            {
                if(!imp.isReadable)
                {
                    imp.isReadable = true;
                    Debug.Log("fix " + path);
                    imp.SaveAndReimport();
                }
            }
        }
 
        AssetDatabase.Refresh();
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_39114763/article/details/132412437