Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
{
private const string kActionIcon = "Packages/com.unity.inputsystem/InputSystem/Editor/Icons/InputAction.png";
private const string kAssetIcon = "Packages/com.unity.inputsystem/InputSystem/Editor/Icons/InputActionAsset.png";
private const string kSettingsIcon = "Packages/com.unity.inputsystem/InputSystem/Editor/Icons/InputSettingsAsset.png";

/// <summary>
/// Attempts to load the icon associated with an <see cref="InputActionAsset"/>.
Expand All @@ -32,6 +33,15 @@
{
return (Texture2D)EditorGUIUtility.Load(kActionIcon);
}

/// <summary>
/// Attempts to load the icon associated with an <see cref="InputSettings"/> asset.
/// </summary>
/// <returns>Icon resource reference or <code>null</code> if the resource could not be loaded.</returns>
internal static Texture2D LoadSettingsIcon()
{
return (Texture2D)EditorGUIUtility.Load(kSettingsIcon);
Comment thread
josepmariapujol-unity marked this conversation as resolved.
}

Check warning on line 44 in Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionAssetIconLoader.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionAssetIconLoader.cs#L42-L44

Added lines #L42 - L44 were not covered by tests
}
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,11 @@
{
// Create and install the settings. This will lead to an InputSystem.onSettingsChange event which in turn
// will cause us to re-initialize.
InputSystem.settings = InputAssetEditorUtils.CreateAsset(ScriptableObject.CreateInstance<InputSettings>(), relativePath);
var settings = ScriptableObject.CreateInstance<InputSettings>();
var icon = InputActionAssetIconLoader.LoadSettingsIcon();
if (icon != null)
EditorGUIUtility.SetIconForObject(settings, icon);
InputSystem.settings = InputAssetEditorUtils.CreateAsset(settings, relativePath);

Check warning on line 218 in Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs#L214-L218

Added lines #L214 - L218 were not covered by tests
Comment thread
josepmariapujol-unity marked this conversation as resolved.
}

private static void CreateNewSettingsAsset()
Expand Down Expand Up @@ -489,6 +493,13 @@
[CustomEditor(typeof(InputSettings))]
internal class InputSettingsEditor : UnityEditor.Editor
{
private void OnEnable()
{
var icon = InputActionAssetIconLoader.LoadSettingsIcon();
if (icon != null)
EditorGUIUtility.SetIconForObject(target, icon);
}

Check warning on line 501 in Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs

View check run for this annotation

Codecov GitHub.com / codecov/patch

Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs#L497-L501

Added lines #L497 - L501 were not covered by tests
Comment on lines +496 to +501
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium
Calling EditorGUIUtility.SetIconForObject inside OnEnable of an Editor is an anti-pattern that can lead to several issues:

  1. Metadata Pollution: For assets, this method modifies the associated .meta file. Calling it in OnEnable ensures the metadata is potentially modified every time the asset is selected or the inspector is refreshed, causing unnecessary noise in Version Control Systems (e.g., Git, Perforce).
  2. Dirtying Assets: It may mark the asset as dirty, triggering "Save Changes" prompts or automatic saves when the user merely viewed the asset.
  3. Import Loops: In some Unity versions, modifying metadata can trigger an asset re-import, which might re-trigger OnEnable, potentially leading to a refresh loop.

It is recommended to set the icon once during asset creation or via an AssetPostprocessor rather than forcing it every time the inspector is enabled.

🤖 Helpful? 👍/👎


public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();
Expand Down
Loading