Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 66daabf

Browse files
committed
Add try/catch to IsNullOrDestroyed
1 parent 9fe998a commit 66daabf

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/Core/Utility/UnityHelpers.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using UnityEngine.UI;
1010
using Object = UnityEngine.Object;
1111

12-
// Project-wide namespace for accessibility
1312
namespace UnityExplorer
1413
{
1514
public static class UnityHelpers
@@ -32,25 +31,28 @@ public static bool OccuredEarlierThan(this float time, float secondsAgo)
3231
/// </summary>
3332
public static bool IsNullOrDestroyed(this object obj, bool suppressWarning = true)
3433
{
35-
var unityObj = obj as Object;
36-
if (obj == null)
34+
try
3735
{
38-
if (!suppressWarning)
39-
ExplorerCore.LogWarning("The target instance is null!");
36+
if (obj == null)
37+
{
38+
if (!suppressWarning)
39+
ExplorerCore.LogWarning("The target instance is null!");
4040

41-
return true;
42-
}
43-
else if (obj is Object)
44-
{
45-
if (!unityObj)
41+
return true;
42+
}
43+
else if (obj is Object unityObj && !unityObj)
4644
{
4745
if (!suppressWarning)
4846
ExplorerCore.LogWarning("The target UnityEngine.Object was destroyed!");
4947

5048
return true;
5149
}
50+
return false;
51+
}
52+
catch
53+
{
54+
return false;
5255
}
53-
return false;
5456
}
5557

5658
/// <summary>

0 commit comments

Comments
 (0)