Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[SOLVED] OnBecameVisible & OnBecameInvisible require Renderer component?

Discussion in 'Scripting' started by Deleted User, May 19, 2016.

  1. Deleted User

    Deleted User

    Guest

    Question
    Do the OnBecameVisible & OnBecameInvisible GO events require the GO to have some kind of Renderer component? The documentation gave me the impression that it is required, but I wanted to be sure.
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    From:
    http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnBecameVisible.html
    Yes, it needs a renderer attached.

    Honestly, how would an object become visible/invisible if it didn't have a renderer? It's the renderer that renders it, giving it something that could be considered 'visible'.
     
    karl_jones and Kiwasi like this.
  3. Deleted User

    Deleted User

    Guest

    @lordofduct
    I wasn't sure because my area of expertise has always been shaders, and I haven't done much with the scripting side of things. Unity does have more than a few odd behaviors, so I thought it better to check.
     
  4. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    Understandable.

    The unity API can be a bit wonky at times.

    I tend to always keep a generic 'test' project around that I can go in and just slap together basic code to test things if I don't know, or the wording is a little confusing. Heck often when answering questions on here for other people, that's really what I'll do first to confirm my answer is correct before posting it.
     
  5. brunoleos

    brunoleos

    Joined:
    May 14, 2014
    Posts:
    30
    The UI components are rendered/visible but its renderer does not inherit from Renderer. So they don't fire the OnBecameVisible/Invisible events.
     
    viesc123 and FaberVi like this.
  6. FaberVi

    FaberVi

    Joined:
    Nov 11, 2014
    Posts:
    145
    Any similar function for UI?
     
  7. eltrexx

    eltrexx

    Joined:
    Feb 1, 2018
    Posts:
    11
    +1 Would be nice to have a callback function if a UI element is visible or not (especially for those UI element outside a scroll View Mask)
     
    FaberVi likes this.
  8. stenfeio

    stenfeio

    Joined:
    Jan 18, 2015
    Posts:
    22
    A callback for UI visibility and invisibility would be extremely helpful as @eltrexx has mentioned. Any ideas as to how to handle checking for if a UI element is hidden behind a mask?