Skip to content

Commit d1d72d5

Browse files
K-ToneCopilot
andauthored
FIX: Address warnings that happened with Unity 6.4 (#2233)
Co-authored-by: Copilot <[email protected]>
1 parent e0d9edc commit d1d72d5

File tree

6 files changed

+65
-15
lines changed

6 files changed

+65
-15
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ however, it has to be formatted properly to pass verification tests.
2424
- Fixed an issue in `RebindingUISample` preventing UI navigation without Keyboard and Mouse present.
2525
- Fixed an issue in `RebindActionUI` which resulted in active binding not being shown after a scene reload. ISXB-1588.
2626
- Fixed an issue in `GamepadIconExample` which resulted in icons for left and right triggers not being displayed after a rebind to the exact same controls. ISXB-1593.
27+
- Fixed the compilation warnings when used with Unity 6.4 (ISX-2349).
2728
- Fixed an issue where `InputSystemUIInputModule.localMultiPlayerRoot` could not be set to `null` when using `MultiplayerEventSystem`. [ISXB-1610](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1610)
2829
- Fixed an issue in `Keyboard` where the sub-script operator would return a `null` key control for the deprecated key `Key.IMESelected`. Now, an aliased `KeyControl`mapping to the IMESelected bit is returned for compability reasons. It is still strongly advised to not rely on this key since `IMESelected` bit isn't strictly a key and will be removed from the `Key` enumeration type in a future major revision. [ISXB-1541](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1541).
2930

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,43 @@ static InputActionEditorWindow()
4242
InputActionAssetEditor.RegisterType<InputActionEditorWindow>();
4343
}
4444

45+
// Unity 6.4 changed signature of OpenAsset, and now it accepts entity id instead of instance id.
46+
[OnOpenAsset]
47+
#if UNITY_6000_4_OR_NEWER
48+
public static bool OpenAsset(EntityId entityId, int line)
49+
{
50+
if (!InputActionImporter.IsInputActionAssetPath(AssetDatabase.GetAssetPath(entityId)))
51+
return false;
52+
53+
return OpenAsset(EditorUtility.EntityIdToObject(entityId));
54+
}
55+
56+
#else
57+
public static bool OpenAsset(int instanceId, int line)
58+
{
59+
if (!InputActionImporter.IsInputActionAssetPath(AssetDatabase.GetAssetPath(instanceId)))
60+
return false;
61+
62+
return OpenAsset(EditorUtility.InstanceIDToObject(instanceId));
63+
}
64+
65+
#endif
66+
4567
/// <summary>
4668
/// Open window if someone clicks on an .inputactions asset or an action inside of it.
4769
/// </summary>
48-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "line", Justification = "line parameter required by OnOpenAsset attribute")]
49-
[OnOpenAsset]
50-
public static bool OnOpenAsset(int instanceId, int line)
70+
private static bool OpenAsset(Object obj)
5171
{
5272
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
5373
if (!InputSystem.settings.useIMGUIEditorForAssets)
5474
return false;
5575
#endif
56-
var path = AssetDatabase.GetAssetPath(instanceId);
57-
if (!InputActionImporter.IsInputActionAssetPath(path))
58-
return false;
59-
6076
string mapToSelect = null;
6177
string actionToSelect = null;
6278

6379
// Grab InputActionAsset.
6480
// NOTE: We defer checking out an asset until we save it. This allows a user to open an .inputactions asset and look at it
6581
// without forcing a checkout.
66-
var obj = EditorUtility.InstanceIDToObject(instanceId);
6782
var asset = obj as InputActionAsset;
6883
if (asset == null)
6984
{

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,36 @@ static InputActionsEditorWindow()
4848
m_Analytics ??= new InputActionsEditorSessionAnalytic(
4949
InputActionsEditorSessionAnalytic.Data.Kind.EditorWindow);
5050

51+
// Unity 6.4 changed signature of OpenAsset, and now it accepts entity id instead of instance id.
5152
[OnOpenAsset]
52-
public static bool OpenAsset(int instanceId, int line)
53+
#if UNITY_6000_4_OR_NEWER
54+
public static bool OpenAsset(EntityId entityId, int line)
5355
{
54-
if (InputSystem.settings.IsFeatureEnabled(InputFeatureNames.kUseIMGUIEditorForAssets))
56+
if (!InputActionImporter.IsInputActionAssetPath(AssetDatabase.GetAssetPath(entityId)))
5557
return false;
58+
59+
return OpenAsset(EditorUtility.EntityIdToObject(entityId));
60+
}
61+
62+
#else
63+
public static bool OpenAsset(int instanceId, int line)
64+
{
5665
if (!InputActionImporter.IsInputActionAssetPath(AssetDatabase.GetAssetPath(instanceId)))
5766
return false;
5867

68+
return OpenAsset(EditorUtility.InstanceIDToObject(instanceId));
69+
}
70+
71+
#endif
72+
73+
private static bool OpenAsset(Object obj)
74+
{
75+
if (InputSystem.settings.IsFeatureEnabled(InputFeatureNames.kUseIMGUIEditorForAssets))
76+
return false;
77+
5978
// Grab InputActionAsset.
6079
// NOTE: We defer checking out an asset until we save it. This allows a user to open an .inputactions asset and look at it
6180
// without forcing a checkout.
62-
var obj = EditorUtility.InstanceIDToObject(instanceId);
6381
var asset = obj as InputActionAsset;
6482

6583
string actionMapToSelect = null;

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3592,8 +3592,7 @@ internal static void InitializeInEditor(IInputRuntime runtime = null)
35923592
}
35933593

35943594
Debug.Assert(settings != null);
3595-
Debug.Assert(EditorUtility.InstanceIDToObject(settings.GetInstanceID()) != null,
3596-
"InputSettings has lost its native object");
3595+
Debug.Assert(HasNativeObject(settings), "InputSettings has lost its native object");
35973596

35983597
// If native backends for new input system aren't enabled, ask user whether we should
35993598
// enable them (requires restart). We only ask once per session and don't ask when
@@ -3696,6 +3695,16 @@ internal static void OnPlayModeChange(PlayModeStateChange change)
36963695
}
36973696
}
36983697

3698+
// We have this function to hide away instanceId -> entityId migration that happened in Unity 6.4
3699+
public static bool HasNativeObject(Object obj)
3700+
{
3701+
#if UNITY_6000_4_OR_NEWER
3702+
return EditorUtility.EntityIdToObject(obj.GetEntityId()) != null;
3703+
#else
3704+
return EditorUtility.InstanceIDToObject(obj.GetInstanceID()) != null;
3705+
#endif
3706+
}
3707+
36993708
private static void OnProjectChange()
37003709
{
37013710
////TODO: use dirty count to find whether settings have actually changed
@@ -3707,7 +3716,7 @@ private static void OnProjectChange()
37073716
// temporary settings object.
37083717
// NOTE: We access m_Settings directly here to make sure we're not running into asserts
37093718
// from the settings getter checking it has a valid object.
3710-
if (EditorUtility.InstanceIDToObject(s_Manager.m_Settings.GetInstanceID()) == null)
3719+
if (!HasNativeObject(s_Manager.m_Settings))
37113720
{
37123721
var newSettings = ScriptableObject.CreateInstance<InputSettings>();
37133722
newSettings.hideFlags = HideFlags.HideAndDontSave;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,11 @@ protected virtual void Awake()
421421
#if UNITY_INPUT_SYSTEM_ENABLE_VR && ENABLE_VR
422422
if (HasStereoCamera(out var cameraComponent))
423423
{
424+
// The Unity 6.4+ replacement for this call has to be figured later
425+
// See https://jira.unity3d.com/browse/XR-7591
426+
#pragma warning disable CS0618
424427
UnityEngine.XR.XRDevice.DisableAutoXRCameraTracking(cameraComponent, true);
428+
#pragma warning restore CS0618
425429
}
426430
#endif
427431
}
@@ -458,7 +462,11 @@ protected virtual void OnDestroy()
458462
#if UNITY_INPUT_SYSTEM_ENABLE_VR && ENABLE_VR
459463
if (HasStereoCamera(out var cameraComponent))
460464
{
465+
// The Unity 6.4+ replacement for this call has to be figured later
466+
// See https://jira.unity3d.com/browse/XR-7591
467+
#pragma warning disable CS0618
461468
UnityEngine.XR.XRDevice.DisableAutoXRCameraTracking(cameraComponent, false);
469+
#pragma warning restore CS0618
462470
}
463471
#endif
464472
}

Packages/com.unity.inputsystem/InputSystem/Utilities/MiscHelpers.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Collections.Generic;
2-
32
namespace UnityEngine.InputSystem.Utilities
43
{
54
internal static class MiscHelpers

0 commit comments

Comments
 (0)