Skip to content

Commit 490dea8

Browse files
authored
fix: Safer version for FindAnyObjectByType (#3765)
Unity docs are a mess on when FindAnyObjectByType was implemented: - 2021.3 says it is - 2022.1 says it's not - 2022.2 says it is
1 parent 2ed1d73 commit 490dea8

8 files changed

Lines changed: 8 additions & 8 deletions

File tree

Assets/Mirror/Examples/BilliardsPredicted/Player/PlayerPredicted.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class PlayerPredicted : NetworkBehaviour
3030
void Awake()
3131
{
3232
// find the white ball once
33-
#if UNITY_2021_3_OR_NEWER
33+
#if UNITY_2022_2_OR_NEWER
3434
whiteBall = FindAnyObjectByType<WhiteBallPredicted>();
3535
#else
3636
// Deprecated in Unity 2023.1

Assets/Mirror/Examples/CharacterSelection/Scripts/PlayerControllerScript.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public override void OnStartAuthority()
8383
characterController.enabled = true;
8484
this.enabled = true;
8585

86-
#if UNITY_2021_3_OR_NEWER
86+
#if UNITY_2022_2_OR_NEWER
8787
sceneReferencer = GameObject.FindAnyObjectByType<SceneReferencer>();
8888
#else
8989
// Deprecated in Unity 2023.1

Assets/Mirror/Examples/CharacterSelection/Scripts/PlayerEmpty.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class PlayerEmpty : NetworkBehaviour
1010
public override void OnStartAuthority()
1111
{
1212
// enable UI located in the scene, after empty player spawns in.
13-
#if UNITY_2021_3_OR_NEWER
13+
#if UNITY_2022_2_OR_NEWER
1414
sceneReferencer = GameObject.FindAnyObjectByType<SceneReferencer>();
1515
#else
1616
// Deprecated in Unity 2023.1

Assets/Mirror/Examples/CouchCoop/Scripts/CouchPlayer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public override void OnStartAuthority()
2626

2727
if (isOwned)
2828
{
29-
#if UNITY_2021_3_OR_NEWER
29+
#if UNITY_2022_2_OR_NEWER
3030
couchPlayerManager = GameObject.FindAnyObjectByType<CouchPlayerManager>();
3131
#else
3232
// Deprecated in Unity 2023.1

Assets/Mirror/Examples/CouchCoop/Scripts/CouchPlayerManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class CouchPlayerManager : NetworkBehaviour
2323
public override void OnStartAuthority()
2424
{
2525
// hook up UI to local player, for cmd communication
26-
#if UNITY_2021_3_OR_NEWER
26+
#if UNITY_2022_2_OR_NEWER
2727
canvasScript = GameObject.FindAnyObjectByType<CanvasScript>();
2828
#else
2929
// Deprecated in Unity 2023.1

Assets/Mirror/Examples/MultipleMatches/Scripts/MatchController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class MatchController : NetworkBehaviour
3333

3434
void Awake()
3535
{
36-
#if UNITY_2021_3_OR_NEWER
36+
#if UNITY_2022_2_OR_NEWER
3737
canvasController = GameObject.FindAnyObjectByType<CanvasController>();
3838
#else
3939
// Deprecated in Unity 2023.1

Assets/Mirror/Examples/MultipleMatches/Scripts/MatchGUI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class MatchGUI : MonoBehaviour
1919

2020
public void Awake()
2121
{
22-
#if UNITY_2021_3_OR_NEWER
22+
#if UNITY_2022_2_OR_NEWER
2323
canvasController = GameObject.FindAnyObjectByType<CanvasController>();
2424
#else
2525
// Deprecated in Unity 2023.1

Assets/Mirror/Examples/_Common/Scripts/CanvasNetworkManagerHUD/CanvasNetworkManagerHUD.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ private void OnClientDisconnect()
188188
// you first add this script to a gameobject.
189189
private void Reset()
190190
{
191-
#if UNITY_2021_3_OR_NEWER
191+
#if UNITY_2022_2_OR_NEWER
192192
if (!FindAnyObjectByType<NetworkManager>())
193193
Debug.LogError("This component requires a NetworkManager component to be present in the scene. Please add!");
194194
#else

0 commit comments

Comments
 (0)