Search Unity

Feedback MonoBehaviour initialization event for inactive GameObjects

Discussion in 'Scripting' started by Mariusz_H, Nov 5, 2020.

  1. Mariusz_H

    Mariusz_H

    Joined:
    May 4, 2018
    Posts:
    15
    As part of “Quality of Life” improvements, can Unity add to MonoBehaviour initialization event for inactive GameObjects? There is a BIG HOLE in Unity’s script life cycle -> Start and Awake are called only for active objects. MonoBehaviour constructor is nasty can of worms, so we need safe initialization event for inactive objects.
     
  2. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,025
    We rely on this for one of our systems where we construct "prefabs" at runtime. We store them under an inactive null to prevent their lifetime methods from being invoked (including awake). This change could break projects like ours that rely on this behaviour, so might not be such a trivial change
     
    DrViJ likes this.
  3. Mariusz_H

    Mariusz_H

    Joined:
    May 4, 2018
    Posts:
    15
    That is why solution shouldn’t change current behavior of Start and Awake. We need new constructor-like event that, if defined, would be called for all objects no matter if they are active.

    People do a lot of hacky/dirty codding to bypass this limitation, so I really hope Unity will find elegant way to patch this omission.
     
  4. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,082
    Since it's related, I take the opportunity to post an older Unite talk where Playdead presented their "PreAwake" and "LateAwake" concepts. It starts around 10:00, video below is with timestamp though:
     
    GliderGuy and SugoiDev like this.
unityunity