From 5db15808e232767ee8913a9cb4726fbce3a7e7ad Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sat, 23 Apr 2022 23:25:31 +0100 Subject: [PATCH] Fixed the UIConnector to safely handle when no parent canvas can be found. Resolves #392 --- Runtime/Scripts/Utilities/UIExtensionMethods.cs | 4 ++++ Runtime/Scripts/Utilities/UILineConnector.cs | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Runtime/Scripts/Utilities/UIExtensionMethods.cs b/Runtime/Scripts/Utilities/UIExtensionMethods.cs index 2b2f10a..3472139 100644 --- a/Runtime/Scripts/Utilities/UIExtensionMethods.cs +++ b/Runtime/Scripts/Utilities/UIExtensionMethods.cs @@ -15,6 +15,10 @@ namespace UnityEngine.UI.Extensions parentCanvas = rt.GetComponentInParent(); if (parentCanvas == null) { + if (parent.parent == null) + { + return null; + } parent = parent.parent.GetComponent(); SearchIndex++; } diff --git a/Runtime/Scripts/Utilities/UILineConnector.cs b/Runtime/Scripts/Utilities/UILineConnector.cs index 6b18000..487dec5 100644 --- a/Runtime/Scripts/Utilities/UILineConnector.cs +++ b/Runtime/Scripts/Utilities/UILineConnector.cs @@ -18,7 +18,11 @@ namespace UnityEngine.UI.Extensions private void Awake() { - canvas = GetComponentInParent().GetParentCanvas().GetComponent(); + var canvasParent = GetComponentInParent().GetParentCanvas(); + if (canvasParent != null) + { + canvas = canvasParent.GetComponent(); + } rt = GetComponent(); lr = GetComponent(); }