Skip to content

Commit fe19081

Browse files
FIX: Avoid making new created assets dirty when opened (#1761)
* Avoid new created assets to be dirty when opened * Add methods to check asset for default json layout and being empty * Improve dirty asset detection when new asset is first created Ideally at this stage, the file on disk should have a serializable equivalent as the serialized asset. However, because the new asset on disk is being created with a specific default json layout, the serialized JSON asset doesn't have not the same content. There are opportunities for change in this area. * Remove default json layout check method * Update renamed constant
1 parent f222c0a commit fe19081

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

Packages/com.unity.inputsystem/InputSystem/Actions/InputActionAsset.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public class InputActionAsset : ScriptableObject, IInputActionCollection2
8383
/// InputActionAssets.
8484
/// </remarks>
8585
public const string Extension = "inputactions";
86+
////REVIEW: actually pre-populate with some stuff?
87+
internal const string kDefaultAssetLayoutJson = "{}";
8688

8789
/// <summary>
8890
/// True if any action in the asset is currently enabled.
@@ -872,6 +874,11 @@ internal void MarkAsDirty()
872874
#endif
873875
}
874876

877+
internal bool IsEmpty()
878+
{
879+
return actionMaps.Count == 0 && controlSchemes.Count == 0;
880+
}
881+
875882
internal void OnWantToChangeSetup()
876883
{
877884
if (m_ActionMaps.LengthSafe() > 0)

Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,12 @@ public override void OnImportAsset(AssetImportContext ctx)
212212
InputActionEditorWindow.RefreshAllOnAssetReimport();
213213
}
214214

215-
////REVIEW: actually pre-populate with some stuff?
216-
private const string kDefaultAssetLayout = "{}";
217-
218215
// Add item to plop an .inputactions asset into the project.
219216
[MenuItem("Assets/Create/Input Actions")]
220217
public static void CreateInputAsset()
221218
{
222219
ProjectWindowUtil.CreateAssetWithContent("New Controls." + InputActionAsset.Extension,
223-
kDefaultAssetLayout, (Texture2D)EditorGUIUtility.Load(kAssetIcon));
220+
InputActionAsset.kDefaultAssetLayoutJson, (Texture2D)EditorGUIUtility.Load(kAssetIcon));
224221
}
225222
}
226223
}

Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,14 @@ private void DirtyInputActionsEditorWindow(InputActionsEditorState newState)
223223
private bool HasAssetChanged(SerializedObject serializedAsset)
224224
{
225225
var asset = (InputActionAsset)serializedAsset.targetObject;
226+
227+
// Checks if the asset being edited is a new asset that was never saved before.
228+
// If it is, there's nothing to save.
229+
// At the moment, an asset only has the default asset layout content on disk when it is first created.
230+
// So in this case we cannot go through the normal path and compare what's on disk with what has been serialized.
231+
if (m_AssetJson == InputActionAsset.kDefaultAssetLayoutJson && asset.IsEmpty())
232+
return false;
233+
226234
var newAssetJson = asset.ToJson();
227235
return newAssetJson != m_AssetJson;
228236
}

0 commit comments

Comments
 (0)