Editor importer broken in Unity 2021 - textures missing on models
stetttho opened this issue · 0 comments
stetttho commented
After updating from Unity 2020 to 2021, on our gltf models the textures were missing. Seems to be a problem with Unity Method AssetDatabase.LoadAssetAtPath only accepting relative paths (like "Assets/xyz/model.gltf") and no full path anymore.
I fixed it temporarily by changing the method CreateTextureAsync in GLTFImage.cs:
public IEnumerator CreateTextureAsync(bool linear, Action<Texture2D> onFinish, Action<float> onProgress = null) {
if (!string.IsNullOrEmpty(path)) {
string relativePath = path.Substring(path.IndexOf("Assets")); // get relative path and then pass it below
#if UNITY_EDITOR
// Load textures from asset database if we can
Texture2D assetTexture = UnityEditor.AssetDatabase.LoadAssetAtPath(relativePath, typeof(Texture2D)) as Texture2D;
if (assetTexture != null) {
onFinish(assetTexture);
if (onProgress != null) onProgress(1f);
yield break;
}
#endif