zwcloud / MeshTerrainEditor-issues

Mesh Terrain Editor issue tracking and online docs
https://zwcloud.github.io/MeshTerrainEditor-issues/
5 stars 3 forks source link

UnityException: Find is not allowed to be called during serialization, call it from OnEnable instead. #159

Closed zwcloud closed 3 years ago

zwcloud commented 3 years ago

reported by user 地编-霞 QQ92xxx64

Describe the bug
When convert a mesh to mesh-terrain with the MTE converter, an error happened and cannot use the converter any more.

zwcloud: This issue is caused by duplicated name when converting a mesh to mesh-terrain.

To Reproduce

  1. Convert a mesh to mesh-terrain with MTE converter.
  2. Convert another mesh to mesh-terrain and use the same output name
  3. Then try to convert again, see the error below and becomes unable to use MTE converter
  4. Restart Unity won't fix the issue
UnityException: Find is not allowed to be called during serialization, call it from OnEnable instead. Called from ScriptableObject 'DockArea'.
See "Script Serialization" page in the Unity Manual for further details.
  at (wrapper managed-to-native) UnityEngine.Shader.Find(string)
  at _ANzlseHsj6ozax0cajiJG9Fq1CQ_.‌‌‌‬‪​‭‌‫‎‬‪‭‭‎‎‍‮‫‫‭‌‍‎‍‌‮ (System.String ) [0x00000] in <271da0b893344abb84d9496308e0dd09>:0 
  at _ANzlseHsj6ozax0cajiJG9Fq1CQ_..ctor () [0x001a6] in <271da0b893344abb84d9496308e0dd09>:0 
  at _vMPjUO45poJ0HhpiBRgs0TgezSc_..ctor () [0x00008] in <271da0b893344abb84d9496308e0dd09>:0 
  at _VbqSdRfFadV4K88bhuddk9J4Rv4_..ctor () [0x0001c] in <271da0b893344abb84d9496308e0dd09>:0 
  at _ONK4faFpqCzcJzO8Q4Fts6BMAcd_..cctor () [0x00000] in <271da0b893344abb84d9496308e0dd09>:0 
Rethrow as TypeInitializationException: The type initializer for '_ONK4faFpqCzcJzO8Q4Fts6BMAcd_' threw an exception.

UnityEditorInternal.InternalEditorUtility:LoadSerializedFileAndForget(String)
UnityEditor.WindowLayout:LoadWindowLayout(String, Boolean) (at D:\unity\Editor\Mono\GUI\WindowLayout.cs:495)

Expected behavior
No error happens and the converter can be used again.

Screenshots
image

Environment

Your solution or workaround
Use a different name for when convert another mesh.

zwcloud commented 3 years ago

We should not allow conversion if target mesh-terrain already exists and notifiy the user about it.

Whatever, the specific exception still needs to be inspected.

zwcloud commented 3 years ago

fixed the exception at https://github.com/zwcloud/MeshTerrainEditor/commit/8a314f5402829aa3a4ea1ca39759dd3270f80c4a