Search Issue Tracker
Won't Fix
Won't Fix in 2023.1.X
Votes
0
Found in
2022.3.2f1
2023.1.0f1
Issue ID
UUM-40618
Regression
No
"Unable to import newly created asset" errors are logged when creating a material from InitializeOnLoad
How to reproduce:
1. Open the attached “IN-44129” project
2. Observe the Console window
Expected result: No errors are displayed in the Console
Actual result: Errors are displayed in the Console
Reproducible with: 2022.3.2f1, 2023.1.0f1
Could not test with: 2021.3.27f1, 2023.2.0a20 - errors with custom packages
Testing environment: macOS 13.2.1 (M1 Max)
Errors:
Unable to import newly created asset : Assets/MyMaterial.mat
UnityEngine.StackTraceUtility:ExtractStackTrace ()
InitializeOnLoadCreateAsset:.cctor () (at Assets/InitializeOnLoadCreateAsset.cs:12)
UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes (System.Type[])
Note: Custom packages are used in the project
Comments (1)
-
y-iwanaga-01
Oct 19, 2023 09:38
A similar error message appears when using Deform 1.2.1 with Unity 2022.3.10f1.
>Unable to import newly created asset : Assets/Deform/EditorResources/DeformSettings.asset
[DeformEditorSettings.cs]
public static class DeformEditorSettings
{
[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"); //<-Here!
}
}
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- “Remove Unused Overrides” available on not loaded Scene and throws “ArgumentException: The scene is not loaded” warning
- Adaptive Probe Volume occlusion edge is calculated incorrectly when viewing probes near geometry edges
- Sampling a texture using an HLSL file throws shader errors and the code does not compile
- "Graphics.CopyTexture called with null source texture" error when Base Camera of an Overlay Camera is removed with DX11 Graphics API and Compatibility Mode enabled
- WebGL sends wrong value with large numbers when SendMessage function is used
Resolution Note:
Asset operations such as asset loading should be avoided in InitializeOnLoad methods. InitializeOnLoad methods are called before asset importing is completed and therefore the asset loading can fail resulting in a null object. To do initialization after a domain reload which requires asset operations use the AssetPostprocessor.OnPostProcessAllAssets callback.
Docs: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/InitializeOnLoadAttribute.html
Resolution Note (2023.1.X):
Asset operations such as asset loading should be avoided in InitializeOnLoad methods. InitializeOnLoad methods are called before asset importing is completed and therefore the asset loading can fail resulting in a null object. To do initialization after a domain reload which requires asset operations use the AssetPostprocessor.OnPostProcessAllAssets callback.
Docs: https://docs.unity3d.com/2023.2/Documentation/ScriptReference/InitializeOnLoadAttribute.html