Skip to content

Commit

Permalink
create settings file deferred because 2022.x complains about CreateAs…
Browse files Browse the repository at this point in the history
…sets call during import
  • Loading branch information
hybridherbst committed Jul 17, 2023
1 parent cdcb744 commit 9838297
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions UnityGLTF/Assets/UnityGLTF/Runtime/Scripts/GLTFSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,22 @@ public static GLTFSettings GetOrCreateSettings()
{
#if UNITY_EDITOR
settings = ScriptableObject.CreateInstance<GLTFSettings>();
settings.name = Path.GetFileNameWithoutExtension(k_RuntimeAndEditorSettingsPath);
var dir = Path.GetDirectoryName(k_RuntimeAndEditorSettingsPath);
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir!);
AssetDatabase.CreateAsset(settings, k_RuntimeAndEditorSettingsPath);
AssetDatabase.SaveAssets();

// we can save it here, but we can't call AssetDatabase.CreateAsset as the importer will complain
UnityEditorInternal.InternalEditorUtility.SaveToSerializedFileAndForget(new UnityEngine.Object[] { settings }, k_RuntimeAndEditorSettingsPath, true);

// so after import, we have to connect the cachedSettings again
EditorApplication.delayCall += () =>
{
// Debug.Log("Deferred settings connection");
AssetDatabase.Refresh();
cachedSettings = null;
TryGetSettings(out var newSettings);
cachedSettings = newSettings;
};
#else
settings = ScriptableObject.CreateInstance<GLTFSettings>();
#endif
Expand Down

0 comments on commit 9838297

Please sign in to comment.