Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public class InputActionAsset : ScriptableObject, IInputActionCollection2
/// InputActionAssets.
/// </remarks>
public const string Extension = "inputactions";
////REVIEW: actually pre-populate with some stuff?
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the content after a save of an empty asset? Not sure why do not initialise it like that when its created? Then we wouldn't need these checks at all and the equality check would solve that for us

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

internal const string kDefaultAssetLayoutJson = "{}";

/// <summary>
/// True if any action in the asset is currently enabled.
Expand Down Expand Up @@ -872,6 +874,11 @@ internal void MarkAsDirty()
#endif
}

internal bool IsEmpty()
{
return actionMaps.Count == 0 && controlSchemes.Count == 0;
}

internal void OnWantToChangeSetup()
{
if (m_ActionMaps.LengthSafe() > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,12 @@ public override void OnImportAsset(AssetImportContext ctx)
InputActionEditorWindow.RefreshAllOnAssetReimport();
}

////REVIEW: actually pre-populate with some stuff?
private const string kDefaultAssetLayout = "{}";

// Add item to plop an .inputactions asset into the project.
[MenuItem("Assets/Create/Input Actions")]
public static void CreateInputAsset()
{
ProjectWindowUtil.CreateAssetWithContent("New Controls." + InputActionAsset.Extension,
kDefaultAssetLayout, (Texture2D)EditorGUIUtility.Load(kAssetIcon));
InputActionAsset.kDefaultAssetLayoutJson, (Texture2D)EditorGUIUtility.Load(kAssetIcon));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,14 @@ private void DirtyInputActionsEditorWindow(InputActionsEditorState newState)
private bool HasAssetChanged(SerializedObject serializedAsset)
{
var asset = (InputActionAsset)serializedAsset.targetObject;

// Checks if the asset being edited is a new asset that was never saved before.
// If it is, there's nothing to save.
// At the moment, an asset only has the default asset layout content on disk when it is first created.
// So in this case we cannot go through the normal path and compare what's on disk with what has been serialized.
if (m_AssetJson == InputActionAsset.kDefaultAssetLayoutJson && asset.IsEmpty())
return false;

var newAssetJson = asset.ToJson();
return newAssetJson != m_AssetJson;
}
Expand Down