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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

IPointerClickHandler and other events are not set up with disabled objects

Discussion in 'Scripting' started by Sombrero13, May 14, 2020.

  1. Sombrero13

    Sombrero13

    Joined:
    Mar 20, 2019
    Posts:
    7
    Found a situation when MonoBehaviour scripts with IPointerClickHandler event interface are not set up with the event system and so they are not working when object activates. Is there any way to register these events manually for Unity event system?
     
  2. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,078
    you probably just need something to click on. To be clear: you need a Graphic component (which is a base class for
    Image
    among others). There you need to make sure that "Raycast Target" is enabled. Otherwise your clicks will go into nowhere.
     
  3. Sombrero13

    Sombrero13

    Joined:
    Mar 20, 2019
    Posts:
    7
    Yep, I've already got it all. The event fired when the object is active from the beginning, but not fired when this object is disabled. So my assumption that the event system just doesn't see this object at the Awake phase and therefore not firing events in runtime. The same problem keeps with the prefab's Instantiating.

    So I guess I need somehow register my object in the event system manually if it is possible at all.
     
  4. Sombrero13

    Sombrero13

    Joined:
    Mar 20, 2019
    Posts:
    7
    Alright, I don't understand a thing. After I added Update() in the script it starts working in both cases. Strange..