Added error handling around setting Unity UI Components for Vertical/Horizontal scrolling

Resolves: https://github.com/Unity-UI-Extensions/com.unity.uiextensions/issues/296
pull/413/head
Simon Jackson 2022-12-24 12:44:23 +00:00
parent 85ee380ee9
commit a317663268
2 changed files with 16 additions and 2 deletions

View File

@ -114,12 +114,20 @@ namespace UnityEngine.UI.Extensions
/// <param name="WorldPositionStays">Should the world position be updated to it's parent transform?</param>
public void AddChild(GameObject GO, bool WorldPositionStays)
{
_scroll_rect.horizontalNormalizedPosition = 0;
try
{
// Rare instances of Unity bug cause error, adding try to manage it.
_scroll_rect.horizontalNormalizedPosition = 0;
}
catch { }
GO.transform.SetParent(_screensContainer, WorldPositionStays);
InitialiseChildObjectsFromScene();
DistributePages();
if (MaskArea)
{
UpdateVisible();
}
SetScrollContainerPosition();
}

View File

@ -114,7 +114,13 @@ namespace UnityEngine.UI.Extensions
/// <param name="WorldPositionStays">Should the world position be updated to it's parent transform?</param>
public void AddChild(GameObject GO, bool WorldPositionStays)
{
_scroll_rect.verticalNormalizedPosition = 0;
try
{
// Rare instances of Unity bug cause error, adding try to manage it.
_scroll_rect.verticalNormalizedPosition = 0;
}
catch { }
GO.transform.SetParent(_screensContainer, WorldPositionStays);
InitialiseChildObjectsFromScene();
DistributePages();