Inexplicable UI flickering in 5.1.0f3

After upgrading my project to Unity 5.1, some of my UI elements have begun to inexplicably flicker and disappear at random. I have scoured the change log looking for a possible explanation but I cannot find any potential culprits. The best way I can explain the problem is with these two short videos:

Working 5.0 UI

Broken 5.1 UI

I have rows of “action buttons” that are made up of various Unity UI elements, but they are primarily just basic buttons with an image component. Each button is instantiated from the same button prefab and they are assigned different sprites to use at runtime. Each button registers itself with an event from another class that will inform it when it needs to perform its update/cooldown routine.

The bulk of the button-updating logic is handled in this script. That script is the only location in the entire project where the sprites are enabled or disabled during runtime. I added two simple debugging messages in the methods that hide the UI elements, but that code is not being reached when the UI is flickering on/off. This leads me to believe that it is a bug on Unity’s end but I’m not sure what more information I can provide to help diagnose it.

The code and logic for handling these buttons was completely unchanged when upgrading from version 5.0 to 5.1. And as you can see in the second video, the UI elements will disappear seemingly randomly when just moving the camera around. Perhaps most perplexing is that only some of the buttons will be affected when they are all instantiated from the same prefab.

I realize I’m not providing much information to work with, but I’m simply not sure what I can do to try and diagnose or fix this problem. If anyone has any advice to help debug this further, or is aware of this being a known bug, I would greatly appreciate any help.

3 Likes

After giving it some more thought, I think this might be related to two Draggable and Droppable scripts I have attached to each button. When viewing the button prefab in the inspector, the check box that usually allows me to enable/disable scripts is not present. The scripts are not generating any compiler warnings or errors though. Is there any reason that the behavior of these scripts may have become broken in this patch?

Can you replicate the issue is a blank scene (or better yet a fresh project)? So that these no other script interfering with it.

Seen similar issues with using prefabs with UI but these were resolved in the 5.0 timeline.

@phil-Unity @Aras any ideas why this is cropping up?

My scripts for these buttons are so highly coupled with others in the project that it would be difficult to test it completely by itself.

I did test it using a button prefab without the Draggable and Droppable scripts mentioned above, but the problem still occurs. I’m going to go ahead and submit a bug report and reference this thread. I’ll submit my entire project if it’s not too large so that they can take a look at it in action.

When some of the icons disappear, can you pause the game and try moving the “invisible” icon around to make sure it’s not rendered underneath its background? I believe your issue is caused by broken UI depth sorting. There were several reports already, people experiencing a similar issue:

1 Like

This does seem to be directly related to my problem. Thank you very much for bringing it to my attention.

I had similar issues, which seem to be gone now that I have removed the child-depth of my UI a bit.

Yeah, my reproduction case consisted of a scene where you can remove a single object and the bug goes away.

Can you elaborate on this? Do you just mean you reduced the number of different nest levels?

This issue still remain in .1p1 :frowning:

I’m also still getting similar flickering in .1p1. Is there any update on this?

Patch 5.1.1p2 fixed it for me.

Thank you for your reply Bennet. I have downloaded 1p2 and I still have a flickering issue. I took a video and made a gif of it which I hope is attached correctly; perhaps this is a different issue to the one you were having then?

What I am doing here is Canvas1.gameobject.setActive(false) and Canvas2.gameobject.SetActive(true) at the same time. It looks like it does some pretty weird stuff!

Canvas1 is basically a ‘landing’ to other menus. Canvas2 is a bunch of InputFields. It looks like Canvas1 is faded off, then on, then off again as Canvas2 is then shown.

2182432--144598--output_4Lq90B.gif

Also I have same issue.

I had the same issue: I fixed it by deactivating the “Pixel Perfect” - Checkbox on the Canvas!

I have the same issue in 5.3. Seems to go away if I have the scene view visible while in play mode.

Hi @Bennett-Lynch , did you managed to fix this issue, I have the same problem and can’t fix it :frowning:

It is a bug in Unity 5.3.x. I uninstalled Unity 5.3.1 and installed Unity 5.2.3. It solved the problem 100%.

1 Like

Hey i have the same problem, im working on Unity 5.4.0p1 and i cant resolve it. Any ideas?

I had this problem with a custom editor window and dynamic textures. I refactored to just pre-allocate the textures into a texture array instead of reusing one texture over and over, and the flickering went away. I was trying to save memory, but oh well.