I’ve just upgraded from 5.1 to 5.2 and now all Image (Script) components in one of my scenes are failing with a NullReferenceException in GetStencilDepth?
Anyone know how to fix this? I’ve tried deleting and reapplying the components, thinking the script behind might be an older version, but no joy. I’ve tried a few other things but can’t get rid of the errors. Everything else seems to work fine but I can’t get these images to display.
If anyone can shed any light on the cause or a possible fix that would be much appreciated!
We ran into the same problem with our project when upgrading to 5.2.
This error message appears to be caused by a Mask Component without a corresponding Image
Component, as shown in the training video UI Mask.
As outlined in the video, while you do not have to have an actual Source Image selected, you do appear to need the Image Component, even if the Source Image is None. This isn’t really clear in the text version of the docs.
Please note that the GameObject in the hierarchy that is linked to the Error message in the log may be a child of the GameObject that has the problem outlined above (as it was in our case), so you may have to look upwards in your hierarchy.
I would imagine there is some additional code now in 5.2 (in UnityEngine.UI.MaskUtilities.GetStencilDepth()) that is not checking for a null reference before using it, which can be fixed by Unity devs, but the root cause is actually our error (of not including the requisite Image Component).
Of course, adding a [RequireComponent(typeof(Image))] to the Mask Component would probably solve the issue altogether, since it seems now that one is required.