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

Is it safe to rely on "OnBecameVisible" in a disabled script?

Discussion in 'Scripting' started by AlanGameDev, Jun 22, 2014.

  1. AlanGameDev

    AlanGameDev

    Joined:
    Jun 30, 2012
    Posts:
    437
    Hello there.

    No one is replying my threads recently :(, so lemme be quick:

    OnBecameVisible is called even when a script is disabled, I'm using that to make the script 'enable' itself, so it goes through "Start" and also the "[x]Update" functions starts to be called every frame/tick.

    I don't know if that's a feature or bug, because intuitively, nothing should run in a disabled script.

    Any ideas if I can use that or is that a bug that will be fixed in the future?

    Thanks in advance.
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
  3. AlanGameDev

    AlanGameDev

    Joined:
    Jun 30, 2012
    Posts:
    437
    Thank you.

    So, if I understand correctly, only Start(), Awake(), Update(), FixedUpdate(), and OnGUI() are affected by disabling the script, however, even for an 'empty' script the checkbox is showing in the editor, what's not consistent with the manual, and also, LateUpdate() is not getting called in a disabled script I have...

    I'm quite confused since I'm not getting what I'm seeing (on the manual :D)... In any case I think it makes sense to call OnBecameVisible even when the script is disabled, so I'm going to rely on that for the moment.
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    The docs should have said LateUpdate (any Update-type functions are not called on a disabled script). Also, the thing about the checkbox in the editor only applies to C# scripts.

    --Eric
     
  5. AlanGameDev

    AlanGameDev

    Joined:
    Jun 30, 2012
    Posts:
    437
    Ok. Thank you.