Fixed the UIConnector to safely handle when no parent canvas can be found.

Resolves #392
pull/413/head
Simon Jackson 2022-04-23 23:25:31 +01:00
parent c059e2338a
commit 5db15808e2
2 changed files with 9 additions and 1 deletions

View File

@ -15,6 +15,10 @@ namespace UnityEngine.UI.Extensions
parentCanvas = rt.GetComponentInParent<Canvas>();
if (parentCanvas == null)
{
if (parent.parent == null)
{
return null;
}
parent = parent.parent.GetComponent<RectTransform>();
SearchIndex++;
}

View File

@ -18,7 +18,11 @@ namespace UnityEngine.UI.Extensions
private void Awake()
{
canvas = GetComponentInParent<RectTransform>().GetParentCanvas().GetComponent<RectTransform>();
var canvasParent = GetComponentInParent<RectTransform>().GetParentCanvas();
if (canvasParent != null)
{
canvas = canvasParent.GetComponent<RectTransform>();
}
rt = GetComponent<RectTransform>();
lr = GetComponent<UILineRenderer>();
}