Search Unity

Add listener to "GameObject.SetActive"?

Discussion in 'Scripting' started by Kvadratt, Apr 14, 2022.

  1. Kvadratt

    Kvadratt

    Joined:
    Mar 7, 2021
    Posts:
    8
    Hello. I'm writing a script that must do things when certain gameObject's "active" state is changed. I could just call some method inside this script instead of "GameObject.SetActive", but i'm curious - is there any way to add listener to GameObject's "SetActive" function, or at least modify GameObject class to make it possible?
     
  2. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    you could define OnEnable and OnDisable messages on that object, then invoke a event other things to subscribe to from it.
     
  3. Kvadratt

    Kvadratt

    Joined:
    Mar 7, 2021
    Posts:
    8
    Oh, right, completely forgot that thing existed. Thanks a lot)