Unity报错:This MeshCollider requires the mesh to be marked.....

拈花ヽ惹草 提交于 2020-01-02 13:40:07

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

解决方法:开启mesh的读写

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

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();
    }
}

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!