Skip to content

Commit

Permalink
-Use UNITY_2021_1 define for AssetDatabase.SaveAssets
Browse files Browse the repository at this point in the history
  • Loading branch information
chuanxin committed May 9, 2022
1 parent a7cca20 commit b41b6d2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Editor/Tiles/RuleOverrideTile/RuleOverrideTileEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,11 @@ private void SaveInstanceTileAsset()
if (assetChanged)
{
EditorUtility.SetDirty(overrideTile.m_InstanceTile);
AssetDatabase.SaveAssetIfDirty(overrideTile.m_InstanceTile);
#if UNITY_2021_1
AssetDatabase.SaveAssets();
#else
AssetDatabase.SaveAssetIfDirty(overrideTile.m_InstanceTile);
#endif
}
}

Expand Down

3 comments on commit b41b6d2

@KonstantinRudolph
Copy link

@KonstantinRudolph KonstantinRudolph commented on b41b6d2 May 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know if you'll answer here, in case you do:
Is this change a workaround for a known bug and fixed someday? Or will AssetDatabase.SaveAssetIfDirty be made obsolete. We're currently running into an issue where our builds fail due to: "error CS0117: 'AssetDatabase' does not contain a definition for 'SaveAssetIfDirty' (new); scripts have compiler errors." inside an editor script residing in a editor-only assembly. And only when building on our build-server, in batch-mode, not when done in editor locally. The documentation of the function does not state anything regarding that issue.
Also posted this on the forums if you'd like to answer there I'd be happy too: In Unity Forums

@ChuanXin-Unity
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this is a workaround for the API (AssetDatabase.SaveAssetIfDirty) that was added to 2021.1.17. Unfortunately, there is no define for specifically identifying if the editor is of version 2021.1.17 and above. As the package is targeting Unity versions 2021.1 and above, but we still want to make use of this API for Unity versions 2021.2 and above, we added this ifdef.

Could you share which version of the Unity Editor you are using for your build server?

@KonstantinRudolph
Copy link

@KonstantinRudolph KonstantinRudolph commented on b41b6d2 May 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks for the reply!
I was pretty sure we'd use the same version on the build server as we use locally, since the whole team updated at the same time. I just checked and saw our build server was still on 2021.1.9f1! That explains the issue, sorry for not double-checking before asking here! 😳

Please sign in to comment.