UniVRM icon indicating copy to clipboard operation
UniVRM copied to clipboard

Unity2020.1系, Unity2019.3系でVRMファイルをインポートできない

Open yuma1217 opened this issue 7 years ago • 4 comments

バグについて

Unity2020.1.0a5や、Unity2019.3.0b3で、VRMファイルをインポートすると、 エラーをいくつか出し、PrefabにはMetaデータしか作成されない

再現方法

動作の再現させる手順:

  1. Unity2020.1系、Unity2019.3系で新規プロジェクトを作成
  2. UniVRM(UniVRM-0.53.0_6b07)をインポート
  3. 適当なVRMファイルをAsset内にドラッグアンドドロップ
  4. 作成されたPrefabとConsoleを見る

期待する動作

Metaデータのみではなく、VrmAvatar, AvatarDescriptionなども生成されてほしい image

環境情報

  • OS: Windows10
  • UniVRM version: UniVRM-0.53.0_6b07

追加の状況・背景

コンソールに出たログです。

GetLoadedImportedAssetsAndTargetHashes called with invalid targetHash
UnityEditor.AssetDatabase:ImportAsset(String)
UniGLTF.UnityPath:ImportAsset() (at Assets/VRM/UniGLTF/Scripts/IO/UnityPath.cs:344)
UniGLTF.UnityPath:EnsureFolder() (at Assets/VRM/UniGLTF/Scripts/IO/UnityPath.cs:363)
UniGLTF.ImporterContext:SaveAsAsset(UnityPath) (at Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs:879)
VRM.<>c__DisplayClass1_0:<ImportVrm>b__0() (at Assets/VRM/UniVRM/Editor/Format/vrmAssetPostprocessor.cs:52)
UnityEditor.EditorApplication:Internal_CallDelayFunctions()

Assertion failed on expression: 'it->second.IsValid()'
UnityEditor.AssetDatabase:ImportAsset(String)
UniGLTF.UnityPath:ImportAsset() (at Assets/VRM/UniGLTF/Scripts/IO/UnityPath.cs:344)
UniGLTF.UnityPath:EnsureFolder() (at Assets/VRM/UniGLTF/Scripts/IO/UnityPath.cs:363)
UniGLTF.ImporterContext:SaveAsAsset(UnityPath) (at Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs:879)
VRM.<>c__DisplayClass1_0:<ImportVrm>b__0() (at Assets/VRM/UniVRM/Editor/Format/vrmAssetPostprocessor.cs:52)
UnityEditor.EditorApplication:Internal_CallDelayFunctions()

GetLoadedImportedAssetsAndTargetHashes called with invalid targetHash
UnityEditor.PrefabUtility:CreatePrefab(String, GameObject)
UniGLTF.ImporterContext:SaveAsAsset(UnityPath) (at Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs:900)
VRM.<>c__DisplayClass1_0:<ImportVrm>b__0() (at Assets/VRM/UniVRM/Editor/Format/vrmAssetPostprocessor.cs:52)
UnityEditor.EditorApplication:Internal_CallDelayFunctions()

Assertion failed on expression: 'it->second.IsValid()'
UnityEditor.PrefabUtility:CreatePrefab(String, GameObject)
UniGLTF.ImporterContext:SaveAsAsset(UnityPath) (at Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs:900)
VRM.<>c__DisplayClass1_0:<ImportVrm>b__0() (at Assets/VRM/UniVRM/Editor/Format/vrmAssetPostprocessor.cs:52)
UnityEditor.EditorApplication:Internal_CallDelayFunctions()

The asset is loaded, but not tracked. source hash='48175948448e7e1fb93a627af0888fa4'
UnityEditor.PrefabUtility:CreatePrefab(String, GameObject)
UniGLTF.ImporterContext:SaveAsAsset(UnityPath) (at Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs:900)
VRM.<>c__DisplayClass1_0:<ImportVrm>b__0() (at Assets/VRM/UniVRM/Editor/Format/vrmAssetPostprocessor.cs:52)
UnityEditor.EditorApplication:Internal_CallDelayFunctions()

AssetImporter is referencing an asset from the previous import. This should not happen.
UnityEditor.PrefabUtility:CreatePrefab(String, GameObject)
UniGLTF.ImporterContext:SaveAsAsset(UnityPath) (at Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs:900)
VRM.<>c__DisplayClass1_0:<ImportVrm>b__0() (at Assets/VRM/UniVRM/Editor/Format/vrmAssetPostprocessor.cs:52)
UnityEditor.EditorApplication:Internal_CallDelayFunctions()

AssetImporter is referencing an asset from the previous import. This should not happen.
UnityEditor.AssetDatabase:ImportAsset(String)
UniGLTF.UnityPath:ImportAsset() (at Assets/VRM/UniGLTF/Scripts/IO/UnityPath.cs:344)
UniGLTF.ImporterContext:SaveAsAsset(UnityPath) (at Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs:904)
VRM.<>c__DisplayClass1_0:<ImportVrm>b__0() (at Assets/VRM/UniVRM/Editor/Format/vrmAssetPostprocessor.cs:52)
UnityEditor.EditorApplication:Internal_CallDelayFunctions()

yuma1217 avatar Oct 01 '19 00:10 yuma1217

It's something to do with the new experimental "Asset Pipeline v2" that Unity is testing out in their newest versions. It's a lot more picky and strange than the old version. It just doesn't like it when you try to do things to newly created assets such as saving them, importing them, or trying to assign references to them in other assets. I suspect it's trying to batch up any file changes for later and so the newly created things don't properly exist yet when they are used later in the code.

I managed to somewhat create a fix for the import issues by changing all occurrences of "PrefabUtility.ReplacePrefab" and "PrefabUtility.CreatePrefab" to "PrefabUtility.SaveAsPrefabAsset". Importing a fresh .vrm file will fail the first time, but then if you Reimport the file everything manages to load in correctly. (Though this was mainly inside the UniGLTF code part of it.) I think it's managing to work because it's only updating the prefab instead of trying to create it from scratch and so the subassets that reference things inside it are able to properly connect to it.

There will still be a lot of "Assertion failed on expression: 'serializedFileIndex != -1'" errors that pop up when things are saved or loaded, but it seems to simply be the new asset pipeline complaining instead of something seriously wrong.

(Interestingly enough, changing the file from a .vrm to a .glb works on it's first try also with a lot those errors.)

Here's a picture showing it working after a Reimport. Capture

I suspect that to fix this problem, you will need to change the importing logic so that the creation and saving of the subassets waits until after the root prefab is saved at least once. To fix all the errors in their entirely might require a intenstive rewrite of the importer code to try and conform to the expectations of the new picky Asset Pipeline. (Or you could try to get Unity to fix things on their end by filing a bug report.)

I would do more but I honestly don't have the additional effort to spare.

ChrisFloofyKitsune avatar Oct 04 '19 08:10 ChrisFloofyKitsune

So thanks! As you say, I changed asset pipe line ver1, importing works well!

yuma1217 avatar Nov 13 '19 08:11 yuma1217

Fixed in v0.54 because there was an error in SubAssets of AssetPiplineV2.

hiroj avatar Dec 13 '19 05:12 hiroj

https://github.com/vrm-c/UniVRM/releases/tag/v0.54.0 fixed version released. If there is a problem, please report again with an issue.

hiroj avatar Dec 18 '19 05:12 hiroj