Skip to content

Commit acdec2d

Browse files
gdgeekkeveleigh
andauthored
Fix object identity APIs for Unity 6.4 and newer (#1136)
* Fix object identity APIs for Unity 6.4 and newer * Update changelogs * Update FindObjectUtility to avoid obsolete sorting APIs on Unity 6.4 --------- Co-authored-by: Kurtis <keveleig@qti.qualcomm.com>
1 parent bb34a67 commit acdec2d

6 files changed

Lines changed: 40 additions & 14 deletions

File tree

‎org.mixedrealitytoolkit.core/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
1818
### Fixed
1919

2020
* Fixed "The type `MixedReality.Toolkit.Core MixedReality.Toolkit.Experimental.BubbleChildHoverEvents/TrickleChildHoverEvents/BubbleChildSelectEvents/TrickleChildSelectEvents` is being serialized by `[SerializeReference]`, but is missing the `[Serializable]` attribute." on Unity 6.3. [PR #1107](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1107)
21+
* Fixed object identity API usages and obsolete sorting warnings for Unity 6.4 and newer in `FindObjectUtility`. [PR #1136](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1136)
2122

2223
## Deprecated
2324

‎org.mixedrealitytoolkit.core/Utilities/FindObjectUtility.cs‎

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ public static class FindObjectUtility
1616
/// Returns the first object matching the specified type.
1717
/// </summary>
1818
/// <remarks>
19-
/// If Unity >= 2021.3.18, calls FindFirstObjectByType. Otherwise calls FindObjectOfType.
19+
/// If Unity >= 6000.4, calls FindAnyObjectByType. If Unity >= 2021.3.18, calls FindFirstObjectByType. Otherwise calls FindObjectOfType.
2020
/// </remarks>
2121
/// <param name="includeInactive">If true, inactive objects will be included in the search. False by default.</param>
2222
public static T FindFirstObjectByType<T>(bool includeInactive = false) where T : Component
2323
{
24-
#if UNITY_2021_3_18_OR_NEWER
25-
return UnityEngine.Object.FindFirstObjectByType<T>(includeInactive ? FindObjectsInactive.Include : FindObjectsInactive.Exclude);
24+
#if UNITY_6000_4_OR_NEWER
25+
return UnityEngine.Object.FindAnyObjectByType<T>(includeInactive ? FindObjectsInactive.Include : FindObjectsInactive.Exclude);
26+
#elif UNITY_2021_3_18_OR_NEWER
27+
return UnityEngine.Object.FindFirstObjectByType<T>(includeInactive ? FindObjectsInactive.Include : FindObjectsInactive.Exclude);
2628
#else
27-
return UnityEngine.Object.FindObjectOfType<T>(includeInactive);
29+
return UnityEngine.Object.FindObjectOfType<T>(includeInactive);
2830
#endif
2931
}
3032

@@ -38,24 +40,26 @@ public static T FindFirstObjectByType<T>(bool includeInactive = false) where T :
3840
public static T FindAnyObjectByType<T>(bool includeInactive = false) where T : Component
3941
{
4042
#if UNITY_2021_3_18_OR_NEWER
41-
return UnityEngine.Object.FindAnyObjectByType<T>(includeInactive ? FindObjectsInactive.Include : FindObjectsInactive.Exclude);
43+
return UnityEngine.Object.FindAnyObjectByType<T>(includeInactive ? FindObjectsInactive.Include : FindObjectsInactive.Exclude);
4244
#else
43-
return UnityEngine.Object.FindObjectOfType<T>(includeInactive);
45+
return UnityEngine.Object.FindObjectOfType<T>(includeInactive);
4446
#endif
4547
}
4648

4749
/// <summary>
4850
/// Returns all objects matching the specified type.
4951
/// </summary>
5052
/// <remarks>
51-
/// If Unity >= 2021.3.18, calls FindObjectsByType. Otherwise calls FindObjectsOfType.
53+
/// If Unity >= 6000.4, calls FindObjectsByType without sorting. If Unity >= 2021.3.18, calls FindObjectsByType. Otherwise calls FindObjectsOfType.
5254
/// </remarks>
5355
/// <param name="includeInactive">If true, inactive objects will be included in the search. False by default.</param>
54-
/// <param name="sort">If false, results will not sorted by InstanceID. True by default.</param>
56+
/// <param name="sort">If false, results will not sorted by InstanceID. True by default. Ignored on Unity 6.4 and newer.</param>
5557
public static T[] FindObjectsByType<T>(bool includeInactive = false, bool sort = true) where T : Component
5658
{
57-
#if UNITY_2021_3_18_OR_NEWER
58-
return UnityEngine.Object.FindObjectsByType<T>(includeInactive ? FindObjectsInactive.Include : FindObjectsInactive.Exclude, sort ? FindObjectsSortMode.InstanceID : FindObjectsSortMode.None);
59+
#if UNITY_6000_4_OR_NEWER
60+
return UnityEngine.Object.FindObjectsByType<T>(includeInactive ? FindObjectsInactive.Include : FindObjectsInactive.Exclude);
61+
#elif UNITY_2021_3_18_OR_NEWER
62+
return UnityEngine.Object.FindObjectsByType<T>(includeInactive ? FindObjectsInactive.Include : FindObjectsInactive.Exclude, sort ? FindObjectsSortMode.InstanceID : FindObjectsSortMode.None);
5963
#else
6064
return UnityEngine.Object.FindObjectsOfType<T>(includeInactive);
6165
#endif
@@ -65,14 +69,16 @@ public static T[] FindObjectsByType<T>(bool includeInactive = false, bool sort =
6569
/// Returns all objects matching the specified type.
6670
/// </summary>
6771
/// <remarks>
68-
/// If Unity >= 2021.3.18, calls FindObjectsByType. Otherwise calls FindObjectsOfType.
72+
/// If Unity >= 6000.4, calls FindObjectsByType without sorting. If Unity >= 2021.3.18, calls FindObjectsByType. Otherwise calls FindObjectsOfType.
6973
/// </remarks>
7074
/// <param name="includeInactive">If true, inactive objects will be included in the search. False by default.</param>
71-
/// <param name="sort">If false, results will not sorted by InstanceID. True by default.</param>
75+
/// <param name="sort">If false, results will not sorted by InstanceID. True by default. Ignored on Unity 6.4 and newer.</param>
7276
/// <param name="type">The type to search for.</param>
7377
public static UnityEngine.Object[] FindObjectsByType(Type type, bool includeInactive = false, bool sort = true)
7478
{
75-
#if UNITY_2021_3_18_OR_NEWER
79+
#if UNITY_6000_4_OR_NEWER
80+
return UnityEngine.Object.FindObjectsByType(type, includeInactive ? FindObjectsInactive.Include : FindObjectsInactive.Exclude);
81+
#elif UNITY_2021_3_18_OR_NEWER
7682
return UnityEngine.Object.FindObjectsByType(type, includeInactive ? FindObjectsInactive.Include : FindObjectsInactive.Exclude, sort ? FindObjectsSortMode.InstanceID : FindObjectsSortMode.None);
7783
#else
7884
return UnityEngine.Object.FindObjectsOfType(type, includeInactive);

‎org.mixedrealitytoolkit.input/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
1313

1414
* Fixed "leaked managed shell" issue in `InteractionModeManager`. [PR #1096](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1096)
1515
* Fixed `EyeCalibrationChecker` build issue on UWP when the Mixed Reality OpenXR Plugin wasn't installed. [PR #1106](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1106)
16+
* Fixed object identity API usages for Unity 6.4 and newer in `InteractionModeManagerEditor`. [PR #1136](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1136)
1617

1718
## [3.3.0] - 2025-11-12
1819

‎org.mixedrealitytoolkit.input/Editor/Inspectors/InteractionModeManagerEditor.cs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,24 @@ private HashSet<string> GetDuplicateControllerMappings()
8080

8181
if (entries != null && entries.arraySize > 0)
8282
{
83+
#if UNITY_6000_4_OR_NEWER
84+
HashSet<EntityId> seenInstanceIDs = new HashSet<EntityId>();
85+
#else
8386
HashSet<int> seenInstanceIDs = new HashSet<int>();
87+
#endif
8488

8589
for (int i = 0; i < entries.arraySize; ++i)
8690
{
8791
SerializedProperty entry = entries.GetArrayElementAtIndex(i);
8892
SerializedProperty key = entry.FindPropertyRelative("key");
8993

94+
#if UNITY_6000_4_OR_NEWER
95+
EntityId instanceID = key != null && key.objectReferenceValue != null ?
96+
key.objectReferenceValue.GetEntityId() : EntityId.None;
97+
#else
9098
int instanceID = key != null && key.objectReferenceValue != null ?
9199
key.objectReferenceValue.GetInstanceID() : 0;
100+
#endif
92101

93102
if (seenInstanceIDs.Contains(instanceID))
94103
{

‎org.mixedrealitytoolkit.spatialmanipulation/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
77
### Fixed
88

99
* Fixed "leaked managed shell" issue in `BoundsCalculator`. [PR #1096](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1096)
10+
* Fixed object identity API usages for Unity 6.4 and newer in `ConstraintManagerEditor`. [PR #1136](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1136)
1011

1112
### Changed
1213

‎org.mixedrealitytoolkit.spatialmanipulation/Editor/Constraints/ConstraintManagerEditor.cs‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,16 @@ public override void OnInspectorGUI()
283283
break;
284284
}
285285

286-
// we render the instance id of this component so our highlighting function can distinguish between
286+
// we render the object id of this component so our highlighting function can distinguish between
287287
// the different instances of constraint manager - highlighting in the inspector is currently
288288
// only available for string search which causes problems with multiple components of the same type
289289
// attached to the same GameObject.
290290
EditorGUILayout.Space();
291+
#if UNITY_6000_4_OR_NEWER
292+
EditorGUILayout.LabelField("ComponentId: " + constraintManager.GetEntityId(), EditorStyles.miniLabel);
293+
#else
291294
EditorGUILayout.LabelField("ComponentId: " + constraintManager.GetInstanceID(), EditorStyles.miniLabel);
295+
#endif
292296

293297
// deferred delete elements from array to not break unity layout
294298
for (int i = indicesToRemove.Count - 1; i > -1; i--)
@@ -370,7 +374,11 @@ public static bool DrawConstraintManagerFoldout(GameObject gameObject, Serialize
370374
if (GUILayout.Button("Go to component"))
371375
{
372376
EditorGUIUtility.PingObject(selectedConstraintManager);
377+
#if UNITY_6000_4_OR_NEWER
378+
Highlighter.Highlight("Inspector", $"ComponentId: {selectedConstraintManager.GetEntityId()}");
379+
#else
373380
Highlighter.Highlight("Inspector", $"ComponentId: {selectedConstraintManager.GetInstanceID()}");
381+
#endif
374382
GUIUtility.ExitGUI();
375383
}
376384
}

0 commit comments

Comments
 (0)