Skip to content

Commit 8e4e35d

Browse files
author
Rene Damm
authored
FIX: Missing InputActionReferences when renaming actions (case 1129145, #1100).
1 parent 2889df9 commit 8e4e35d

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ however, it has to be formatted properly to pass verification tests.
2020

2121
#### Actions
2222

23+
- References to `InputActionReference` objects created by the importer for `.inputactions` files are no longer broken when the action referenced by the object is renamed ([case 1229145](https://issuetracker.unity3d.com/issues/inputsystem-inputactionreference-loses-guid-when-its-action-is-moved-or-renamed-in-the-inputaction-asset)).
24+
* __THIS IS A BREAKING CHANGE__: Unfortunately, this change impacts Unity internal file IDs of `InputActionReference` objects created by the `.inputactions` file importer. This means that previously created references to `InputActionReference` objects will become missing and need to be recreated.
25+
* __HOW TO FIX BROKEN REFERENCES__: Locate the sub-object in the `.inputactions` asset for the action you are referencing and replace the now missing references with the newly created objects.
2326
- Controls are now re-resolved after adding or removing bindings from actions ([case 1218544](https://issuetracker.unity3d.com/issues/input-system-package-does-not-re-resolve-bindings-when-adding-a-new-binding-to-a-map-that-has-already-generated-its-state)).
2427
- Can now have spaces and special characters in action names when using `PlayerInput` with the `SendMessages` or `BroadcastMessages` behavior. Previously, an incorrect method name was generated (fix contributed by [BHSPitMonkey](https://github.com/BHSPitMonkey) in [#1022](https://github.com/Unity-Technologies/InputSystem/pull/1022); [case 1214519](https://issuetracker.unity3d.com/issues/player-input-send-messages-wont-trigger-when-input-action-name-contains-spaces)).
2528
- Adding a new action now sets `expectedControlType` to `Button` as expected ([case 1221015](https://issuetracker.unity3d.com/issues/input-system-default-value-of-expectedcontroltype-is-not-being-set-when-creating-a-new-action)).

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
using System;
22
using System.Linq;
33

4+
////REVIEW: Can we somehow make this a simple struct? The one problem we have is that we can't put struct instances as sub-assets into
5+
//// the import (i.e. InputActionImporter can't do AddObjectToAsset with them). However, maybe there's a way around that. The thing
6+
//// is that we really want to store the asset reference plus the action GUID on the *user* side, i.e. the referencing side. Right
7+
//// now, what happens is that InputActionImporter puts these objects along with the reference and GUID they contain in the
8+
//// *imported* object, i.e. right with the asset. This partially defeats the whole purpose of having these objects and it means
9+
//// that now the GUID doesn't really matter anymore. Rather, it's the file ID that now has to be stable.
10+
////
11+
//// If we always store the GUID and asset reference on the user side, we can put the serialized data *anywhere* and it'll remain
12+
//// save and proper no matter what we do in InputActionImporter.
13+
414
////REVIEW: should this throw if you try to assign an action that is not a singleton?
515

616
////REVIEW: akin to this, also have an InputActionMapReference?
@@ -49,7 +59,7 @@ public InputAction action
4959
if (m_Asset == null)
5060
return null;
5161

52-
m_Action = m_Asset.FindAction(new Guid(m_ActionId));
62+
m_Action = m_Asset.FindAction(m_ActionId);
5363
}
5464

5565
return m_Action;

Packages/com.unity.inputsystem/InputSystem/Editor/AssetEditor/InputActionAssetManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System.IO;
44
using UnityEditor;
55

6+
////TODO: ensure that GUIDs in the asset are unique
7+
68
namespace UnityEngine.InputSystem.Editor
79
{
810
/// <summary>

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#if UNITY_EDITOR
22
using System;
33
using System.IO;
4+
using System.Linq;
45
using UnityEditor;
56
using UnityEditor.Experimental.AssetImporters;
67
using UnityEngine.InputSystem.Utilities;
@@ -22,7 +23,7 @@ namespace UnityEngine.InputSystem.Editor
2223
[ScriptedImporter(kVersion, InputActionAsset.Extension)]
2324
internal class InputActionImporter : ScriptedImporter
2425
{
25-
private const int kVersion = 10;
26+
private const int kVersion = 11;
2627

2728
private const string kActionIcon = "Packages/com.unity.inputsystem/InputSystem/Editor/Icons/InputAction.png";
2829
private const string kAssetIcon = "Packages/com.unity.inputsystem/InputSystem/Editor/Icons/InputActionAsset.png";
@@ -90,25 +91,27 @@ public override void OnImportAsset(AssetImportContext ctx)
9091
ctx.AddObjectToAsset("<root>", asset, assetIcon);
9192
ctx.SetMainObject(asset);
9293

93-
// Make sure all the elements in the asset have GUIDs.
94+
// Make sure all the elements in the asset have GUIDs and that they are indeed unique.
9495
var maps = asset.actionMaps;
9596
foreach (var map in maps)
9697
{
9798
// Make sure action map has GUID.
98-
if (string.IsNullOrEmpty(map.m_Id))
99+
if (string.IsNullOrEmpty(map.m_Id) || asset.actionMaps.Count(x => x.m_Id == map.m_Id) > 1)
99100
map.GenerateId();
100101

101102
// Make sure all actions have GUIDs.
102103
foreach (var action in map.actions)
103104
{
104-
if (string.IsNullOrEmpty(action.m_Id))
105+
var actionId = action.m_Id;
106+
if (string.IsNullOrEmpty(actionId) || asset.actionMaps.Sum(m => m.actions.Count(a => a.m_Id == actionId)) > 1)
105107
action.GenerateId();
106108
}
107109

108110
// Make sure all bindings have GUIDs.
109111
for (var i = 0; i < map.m_Bindings.LengthSafe(); ++i)
110112
{
111-
if (string.IsNullOrEmpty(map.m_Bindings[i].m_Id))
113+
var bindingId = map.m_Bindings[i].m_Id;
114+
if (string.IsNullOrEmpty(bindingId) || asset.actionMaps.Sum(m => m.bindings.Count(b => b.m_Id == bindingId)) > 1)
112115
map.m_Bindings[i].GenerateId();
113116
}
114117
}
@@ -128,7 +131,7 @@ public override void OnImportAsset(AssetImportContext ctx)
128131
objectName = $"{map.name}/{action.name}";
129132

130133
actionReference.name = objectName;
131-
ctx.AddObjectToAsset(objectName, actionReference, actionIcon);
134+
ctx.AddObjectToAsset(action.m_Id, actionReference, actionIcon);
132135
}
133136
}
134137

0 commit comments

Comments
 (0)