keenanwoodall / Deform

A fully-featured deformer system for Unity that lets you stack effects to animate models in real-time

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The following error occurs when importing in Unity 2022.3 : Unable to import newly created asset

mokuseijin opened this issue · comments

Describe the bug
When using Deform with Unity 2022.3, this occurs when importing the Deform package.

It seems that Deform falls under the issue of Issue-Tracer below:
https://issuetracker.unity3d.com/issues/unable-to-import-newly-created-asset-errors-are-logged-when-creating-a-material-from-initializeonload

To Reproduce
Start a project using Deform with Unity 2022.3.10 etc. with the Library folder deleted.
The following error message will be output:
Unable to import newly created asset : Assets/Deform/EditorResources/DeformSettings.asset.
UnityEngine.StackTraceUtility:ExtractStackTrace ()
DeformEditor.DeformEditorResources:CreateAsset (UnityEngine.Object,string) (at ./Packages/com.beans.deform@7d7b19147b/Code/Editor/DeformEditorResources.cs:52)
DeformEditor.DeformEditorSettings:EnsureSettingsAsset () (at ./Packages/com.beans.deform@7d7b19147b/Code/Editor/DeformEditorSettings.cs:16)
UnityEditor.EditorAssemblies:ProcessInitializeOnLoadMethodAttributes ()

Expected behavior
none

Screenshots
none

Additional context
Below is the code I implemented to avoid the error:

#if AVOID_UNABLE_TO_IMPORT_NEWLY_CREATED_ASSET
    public class DeformAssetPostprocessor : AssetPostprocessor
    {
        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            if (DeformEditorSettings.requestCreateDeformSettings)
            {
                //Create the DeformSettings.asset at this timing according to the 'requestCreateDeformSettings'.
                DeformEditorSettings.CreateSettingsAsset();
            }
        }
    }
#endif//AVOID_UNABLE_TO_IMPORT_NEWLY_CREATED_ASSET
    public static class DeformEditorSettings
    {
#if AVOID_UNABLE_TO_IMPORT_NEWLY_CREATED_ASSET
        [InitializeOnLoadMethod]
        private static void EnsureSettingsAsset()
        {
            if (settingsAsset == null)
            {
                settingsAsset = DeformEditorResources.LoadAssetOfType<DeformEditorSettingsAsset>(searchAssets: DeformEditorResources.SearchFilter.Assets);
            }
            if (settingsAsset == null)
            {
                //Create instance of 'settingsAsset'  here.
                settingsAsset = ScriptableObject.CreateInstance<DeformEditorSettingsAsset>();
                //However, if create asset here, an error will occur in Unity 2022.
                //Therefore, postpone it using the creation request flag 'requestCreateDeformSettings'.
                requestCreateDeformSettings = true;
            }
        }
        internal static void CreateSettingsAsset()
        {
            if (requestCreateDeformSettings)
            {
                Debug.Assert(settingsAsset != null);
                DeformEditorResources.CreateAsset(settingsAsset, "Deform/EditorResources/DeformSettings.asset");
                requestCreateDeformSettings = false;
            }
        }
        internal static bool requestCreateDeformSettings = false;
#else//AVOID_UNABLE_TO_IMPORT_NEWLY_CREATED_ASSET
        //ORIGINAL CODE
        [InitializeOnLoadMethod]
        private static void EnsureSettingsAsset ()
        {
            if (settingsAsset == null)
                settingsAsset = DeformEditorResources.LoadAssetOfType<DeformEditorSettingsAsset> (searchAssets: DeformEditorResources.SearchFilter.Assets);
            if (settingsAsset == null)
            {
                settingsAsset = ScriptableObject.CreateInstance<DeformEditorSettingsAsset> ();
                DeformEditorResources.CreateAsset (settingsAsset, "Deform/EditorResources/DeformSettings.asset");
            }
        }
#endif//AVOID_UNABLE_TO_IMPORT_NEWLY_CREATED_ASSET

Thank you for creating and documenting this issue. I am abroad and computer-less through October and the first half of November so unfortunately I cannot implement or test this fix. My apologies for the inconvenience - I will take a closer look as soon as I am able. Thanks again for finding the issue and putting together a solution!