OnBecameVisible does not fire for CanvasRenderers

Not sure if this is a bug or by design, but I noticed that the OnBecameVisible event does not fire for UI widgets (CanvasRenderers). As soon as I add a MeshRenderer to my object, the event fires.

Should this be firing? If not, is there an appropriate way to determine when a UI widget comes on screen? My use case is a long scrolling list of widgets that I only want to initialize once they are visible.

I know I could just do some kind of RectTransform calculations in Update, but I was hoping for something more efficient/built-in.

Yea we dont have anything like onBecameVisible for UI widgets, this is by “design”. Everything is technically visible from the codes perspective (even if its being hidden by a mask). We will eventually start culling things but thats a while out yet.

1 Like

Would there be any reason to avoid putting mesh renderers on UI elements that you wanted to track in this way? I’m having the same kind of issue as casimps1 with a scroll list where I run into issues when updating just from scroll rect OnValueChanged so I think i’ll have to change it to Update, which I would like to avoid. If I can simply add mesh renderers to the specific UI elements and use OnBecameVisible/Invisible that would probably work much better.

Sorry for necroing an old post, but I had to do something similar today, although I avoided trying to mimic the callback OnBecameVisible/OnBecameInvisible and instead used a coroutine to check once in a while (0.5s intervals) for visibility, as I wanted to start a UI animation when a particular UI element became fully visible on screen.

Here’s a link to another forum answer where I posted the code: Test if UI element is visible on screen - Unity Engine - Unity Discussions

Hope this helps someone out there :slight_smile:

2 Likes

In my current case, working in RV, I am putting a canvas at the user’s feet, which is not always visible, and whose calculations I want to do only when it is.

Canvases can be in world space and other situations than in front of the camera, so will be usefull if UI renderers send this message too.

2 Likes

Any word on this?

Having such functionality would have been handy for me right now too. I would like to only update UI widgets that are visible in their ScrollView.

Is OnBecameVisible or similar functionality for UI on the roadmap?

4 Likes

Also would like to see something like OnBecameVisible for ui
including hidding by masks.

I need an event when UI item became visible while scrooling to send an api call to server to retrieve profile photo. I am really surprised unity doesnt have such a method. @phil-Unity you can at least show us a way to do it???

Every maskable graphic (i.e. everything that renders that Unity provides) have a onCullStateChanged event that is triggered. assuming you have a Mask or RectMask2D on the scrollview you should be able to have a script that ties into that callback.

I was in the need of OnBecameVisible & OnBecameInvisible events on uGUI widgets recently once again and decided to implement a generic Component to do the job.

I call the Component UICullingBehaviour and I released it in the form of a Unity package on github under the MIT license.

1 Like

How we can set viewport runtime?