Unexpected Behavior With Rect Mask 2d When Instantiating Off Screen

This bug has riddled out app with unexpected behavior with all of our components which contain a Rect Mask 2d. We often instantiate a Scroll View game object off screen, then slide it on screen. Doing so however seems to break the Rect Mask 2d expected behavior, and the masks often don’t work, and further sliding animations stop working.

One slight workaround that works in some cases is to wait to activate the Rect Mask 2d until it is on screen fully.

public class BodyMaskActivator : MonoBehaviour
{
    public UnityEvent maskActivated;
    public bool isUnmasked = true;
    void Start()
    {
        StartCoroutine(WaitThenActivate());
    }
    IEnumerator WaitThenActivate()
    {
        yield return new WaitForSeconds(.7f);
        if (this.GetComponent<RectMask2D>())
        {
            this.GetComponent<RectMask2D>().enabled = true;
            maskActivated.Invoke();
            isUnmasked = false;
        }
    }
}

However, this is inconsistent and in many cases, waiting .7f seconds to activate the mask causes all the unwanted hidden masked objects to show until the script is activated.

Has anyone experienced this issue? Any info on a possible workaround and fix would hugely help us move forward with polishing off our UI and launching our app.

Thank you Unity community. We are currently using version 2019.4.8f1

3 more hours later, the problem was solved.

We were instantiating the scroll rect object in a separate off screen game object (a staging canvas), then before the slide into view, changing the parent from the off screen staging canvas, to the new base sliding panel.

We instead instantiate the scroll rect object into the existing on screen base sliding panel, and to give it the off screen effect for UI sake, we set the position off screen. Then once the base sliding panel has slid off screen, we change the position of the scroll rect object back to its original position, and then the base sliding panel slides back up into view.

Just wanted to add that I am also experiencing this behavior and find it really strange. Glad to know I’m not the only one though.