mitay-walle / com.mitay-walle.gradient-texture

Unity Gradient Texture generator
MIT License
86 stars 12 forks source link

Null Reference Exception on Asset create #23

Closed fleity closed 1 year ago

fleity commented 1 year ago

When creating a new gradient asset using right click > texture > gradient unity creates the scriptable object but the texture asset is not immediately created instead unity logs this error (26 times) image

NullReferenceException
Packages.GradientTextureGenerator.Editor.GradientTextureEditor.RenderStaticPreview (System.String assetPath, UnityEngine.Object[] subAssets, System.Int32 width, System.Int32 height) (at Library/PackageCache/com.mitay-walle.gradient-texture@64ad373442/Editor/GradientTextureEditor.cs:130)
UnityEditor.AssetPreviewUpdater.CreatePreview (UnityEngine.Object obj, UnityEngine.Object[] subAssets, System.String assetPath, System.Int32 width, System.Int32 height) (at <ee6fd03ff96245f993c3cba83ed9657b>:0)
UnityEditor.AssetPreviewUpdater.CreatePreviewForAsset (UnityEngine.Object obj, UnityEngine.Object[] subAssets, System.String assetPath) (at <ee6fd03ff96245f993c3cba83ed9657b>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
[Worker0] Refresh completed but there are assets queued up for importing. Check for code that modifies assets which gets called after OnPostProcessAllAssets. Additional details in Log file
[Worker0] The asset at Assets/NewGradientName 3.asset has been scheduled for reimport during the Refresh loop and Loading of it has been attempted.
Doing this can lead to the AssetDatabase returning two versions of the same asset.
Please ensure that code which attempts to reimport this asset does not run while the editor is Refreshing.
You can do so by checking the value of EditorApplication.isUpdating

After applying any change to the gradient asset this warning appears and the texture is generated successfully

Importer(NativeFormatImporter) generated inconsistent result for asset(guid:c77e8c2b0655d5749b218eb19c9234df) "Assets/NewGradientName 3.asset"
UnityEngine.StackTraceUtility:ExtractStackTrace ()
Packages.GradientTextureGenerator.Runtime.GradientTexture:OnValidate () (at Library/PackageCache/com.mitay-walle.gradient-texture@64ad373442/Runtime/GradientTexture.cs:132)
UnityEditor.Editor:OnInspectorGUI ()
Packages.GradientTextureGenerator.Editor.GradientTextureEditor:OnInspectorGUI () (at Library/PackageCache/com.mitay-walle.gradient-texture@64ad373442/Editor/GradientTextureEditor.cs:25)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

The error is only a minor issue as it does not prevent the asset from being used but it is a bad user experience. (Version 1.0.7 with srgb toggle, Unity 2022.1.4f1)

mitay-walle commented 1 year ago
  1. RenderStaticPreview - fixed
  2. [Worker] Refresh completed - fixed
  3. [Worker] asset scheduled for reimport - fixed
  4. Importer generated inconsistent result - this message appear, if you name new asset as previos in same folder, it's not related to GradientTexture itself

I've do my best to minimize error messages, but Inspector Preview is realy hacky, and there still 1 message: "ArgumentException: Getting control 2's position in a group with only 2 controls when doing repaint"

I'll create separated issue for this

fleity commented 1 year ago

Thank you so much for working on it so quickly, huge improvement already 👍 I can relate to preview being really annoying. It seems especially that unity version does have a lot of problems there to make matters worse.