Skip to content

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

@mokuseijin

Description

@mokuseijin

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions