Skip to content

Commit ff181b1

Browse files
authored
FIX: Fix TrackedPoseDriver serialization migration (ISXB-512, ISXB-521) (#1705)
* Fixed serialization migration in TrackedPoseDriver when prefabs are used - Removed the no longer necessary m_HasMigratedActions field since it only copies over from the old deprecated fields if the new property has not been initialized. - This fix still does not fix the issue of nested prefabs where the parent prefab has an override to add a new input binding. The base prefab will already have the InputActionProperty upgraded, so the modified old deprecated field with the additional singleton bindings doesn't get copied over to the new property. There doesn't seem to be a way to reliably detect this situation. * Fixed flags not being copied in Clone methods and fixed so a Guid is generated for actions in constructor - When adding a serialized InputAction (or with an InputActionProperty), the ID Guid may not be generated, which could cause noise in prefab overrides. Having the constructor generate an ID initially instead of relying on the id property or property drawer generate one and write to the asset makes it more consistent. This specifically fixes the GameObject > XR > XR Origin (VR) creation shortcut not having IDs set since the Inspector is never visible before making a prefab. * Fixed changelog after merge of 1.6.2 release * Fixed changelog to put new stuff in Unreleased section, not 1.6.2 * Added property getter for the fields instead of making the fields internal - We can potentially make the new properties public and even add setters along with a property for useReference, but this way of keeping them internal will avoid having to bump minor version to fix this bug.
1 parent e8bbe3d commit ff181b1

7 files changed

Lines changed: 42 additions & 24 deletions

File tree

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ however, it has to be formatted properly to pass verification tests.
1010

1111
## [Unreleased]
1212

13-
### Fixed
14-
- Fixed missing prefab errors in InputDeviceTester project (case ISXB-420).
15-
1613
### Added
1714
- Preliminary support for visionOS.
1815

16+
### Changed
17+
- Changed the `InputAction` constructors so it generates an ID for the action and the optional binding parameter. This is intended to improve the serialization of input actions on behaviors when created through API when the property drawer in the Inspector window does not have a chance to generate an ID.
18+
19+
### Fixed
20+
- Fixed missing prefab errors in InputDeviceTester project ([case ISXB-420](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-420)).
21+
- Fixed serialization migration in the Tracked Pose Driver component causing bindings to clear when prefabs are used in some cases ([case ISXB-512](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-512), [case ISXB-521](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-521)).
22+
- Fixed the `Clone` methods of `InputAction` and `InputActionMap` so it copies the Initial State Check flag (`InputAction.wantsInitialStateCheck`) of input actions.
1923

2024
## [1.6.3] - 2023-07-11
2125

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ public bool wantsInitialStateCheck
669669
/// </remarks>
670670
public InputAction()
671671
{
672+
m_Id = Guid.NewGuid().ToString();
672673
}
673674

674675
/// <summary>
@@ -724,8 +725,9 @@ public InputAction(string name = null, InputActionType type = default, string bi
724725
path = binding,
725726
interactions = interactions,
726727
processors = processors,
727-
action = m_Name
728-
}
728+
action = m_Name,
729+
id = Guid.NewGuid(),
730+
},
729731
};
730732
m_BindingsStartIndex = 0;
731733
m_BindingsCount = 1;
@@ -737,6 +739,7 @@ public InputAction(string name = null, InputActionType type = default, string bi
737739
}
738740

739741
m_ExpectedControlType = expectedControlType;
742+
m_Id = Guid.NewGuid().ToString();
740743
}
741744

742745
/// <summary>
@@ -913,6 +916,7 @@ public InputAction Clone()
913916
m_ExpectedControlType = m_ExpectedControlType,
914917
m_Interactions = m_Interactions,
915918
m_Processors = m_Processors,
919+
m_Flags = m_Flags,
916920
};
917921
return clone;
918922
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ public InputActionMap Clone()
596596
m_Interactions = original.m_Interactions,
597597
m_Processors = original.m_Processors,
598598
m_ExpectedControlType = original.m_ExpectedControlType,
599+
m_Flags = original.m_Flags,
599600
};
600601
}
601602
clone.m_Actions = actions;

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ namespace UnityEngine.InputSystem
2929
public struct InputActionProperty : IEquatable<InputActionProperty>, IEquatable<InputAction>, IEquatable<InputActionReference>
3030
{
3131
/// <summary>
32-
/// The action held on to by the property.
32+
/// The effective action held on to by the property.
3333
/// </summary>
34-
/// <value>The action object contained in the property.</value>
34+
/// <value>The effective action object contained in the property.</value>
3535
/// <remarks>
3636
/// This property will return <c>null</c> if the property is using a <see cref="reference"/> and
3737
/// the referenced action cannot be found. Also, it will be <c>null</c> if the property
@@ -41,12 +41,24 @@ public struct InputActionProperty : IEquatable<InputActionProperty>, IEquatable<
4141
public InputAction action => m_UseReference ? m_Reference != null ? m_Reference.action : null : m_Action;
4242

4343
/// <summary>
44-
/// If the property contains a reference to the action, this property returns
44+
/// If the property is set to use a reference to the action, this property returns
4545
/// the reference. Otherwise it returns <c>null</c>.
4646
/// </summary>
4747
/// <value>Reference to external input action, if defined.</value>
4848
public InputActionReference reference => m_UseReference ? m_Reference : null;
4949

50+
/// <summary>
51+
/// The serialized loose action created in code serialized with this property.
52+
/// </summary>
53+
/// <value>The serialized action field.</value>
54+
internal InputAction serializedAction => m_Action;
55+
56+
/// <summary>
57+
/// The serialized reference to an external action.
58+
/// </summary>
59+
/// <value>The serialized reference field.</value>
60+
internal InputActionReference serializedReference => m_Reference;
61+
5062
/// <summary>
5163
/// Initialize the property to contain the given action.
5264
/// </summary>

Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputActionDrawer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#if UNITY_EDITOR
2+
using System;
23
using UnityEditor;
34
using UnityEditor.IMGUI.Controls;
45

@@ -52,7 +53,7 @@ protected override void ResetProperty(SerializedProperty property)
5253
{
5354
if (property == null) return;
5455

55-
property.SetStringValue(nameof(InputAction.m_Id), "");
56+
property.SetStringValue(nameof(InputAction.m_Id), Guid.NewGuid().ToString());
5657
property.SetStringValue(nameof(InputAction.m_Name), "Input Action");
5758
property.FindPropertyRelative(nameof(InputAction.m_SingletonActionBindings))?.ClearArray();
5859
property.serializedObject?.ApplyModifiedPropertiesWithoutUndo();

Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/InputActionMapDrawer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#if UNITY_EDITOR
2+
using System;
23
using UnityEditor;
34
using UnityEditor.IMGUI.Controls;
45

@@ -52,7 +53,7 @@ protected override void ResetProperty(SerializedProperty property)
5253
{
5354
if (property == null) return;
5455

55-
property.SetStringValue(nameof(InputActionMap.m_Id), "");
56+
property.SetStringValue(nameof(InputActionMap.m_Id), Guid.NewGuid().ToString());
5657
property.SetStringValue(nameof(InputActionMap.m_Name), "Input Action Map");
5758
property.FindPropertyRelative(nameof(InputActionMap.m_Actions))?.ClearArray();
5859
property.FindPropertyRelative(nameof(InputActionMap.m_Bindings))?.ClearArray();

Packages/com.unity.inputsystem/InputSystem/Plugins/XR/TrackedPoseDriver.cs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,6 @@ void OnTrackingStateCanceled(InputAction.CallbackContext context)
397397
/// </summary>
398398
protected void Reset()
399399
{
400-
m_HasMigratedActions = true;
401-
402400
m_PositionInput = new InputActionProperty(new InputAction("Position", expectedControlType: "Vector3"));
403401
m_RotationInput = new InputActionProperty(new InputAction("Rotation", expectedControlType: "Quaternion"));
404402
m_TrackingStateInput = new InputActionProperty(new InputAction("Tracking State", expectedControlType: "Integer"));
@@ -636,12 +634,6 @@ public InputAction rotationAction
636634
#pragma warning restore 0649
637635
// ReSharper restore UnassignedField.Local
638636

639-
/// <summary>
640-
/// Stores whether the fields of type <see cref="InputAction"/> have been migrated to fields of type <see cref="InputActionProperty"/>.
641-
/// </summary>
642-
[SerializeField, HideInInspector]
643-
bool m_HasMigratedActions;
644-
645637
/// <inheritdoc />
646638
void ISerializationCallbackReceiver.OnBeforeSerialize()
647639
{
@@ -650,13 +642,16 @@ void ISerializationCallbackReceiver.OnBeforeSerialize()
650642
/// <inheritdoc />
651643
void ISerializationCallbackReceiver.OnAfterDeserialize()
652644
{
653-
if (m_HasMigratedActions)
654-
return;
645+
#pragma warning disable 0612 // Type or member is obsolete -- Deprecated fields are migrated to new properties.
646+
#pragma warning disable UNT0029 // Pattern matching with null on Unity objects -- Using true null is intentional, not operator== evaluation.
647+
// We're checking for true null here since we don't want to migrate if the new field is already being used, even if the reference is missing.
648+
// Migrate the old fields to the new properties added in Input System 1.1.0-pre.6.
649+
if (m_PositionInput.serializedReference is null && m_PositionInput.serializedAction is null && !(m_PositionAction is null))
650+
m_PositionInput = new InputActionProperty(m_PositionAction);
655651

656-
#pragma warning disable 0612
657-
m_PositionInput = new InputActionProperty(m_PositionAction);
658-
m_RotationInput = new InputActionProperty(m_RotationAction);
659-
m_HasMigratedActions = true;
652+
if (m_RotationInput.serializedReference is null && m_RotationInput.serializedAction is null && !(m_RotationAction is null))
653+
m_RotationInput = new InputActionProperty(m_RotationAction);
654+
#pragma warning restore UNT0029
660655
#pragma warning restore 0612
661656
}
662657

0 commit comments

Comments
 (0)