Search Feedback

97
votes

Add a function like Awake() that is called even on inactive objects

Scripting

-

-

It's often useful to start objects in a disabled state, especially if they are only going to be present in the game under specific circumstances and you also don't want them visually cluttering up the editor. For example menu screens cover everything in the editor and are only displayed when the player brings them up.

However when objects start disabled, their Awake functions are not called which can cause problems when you try to use them and they aren't initialised properly.

Ideally Awake() would still be called on disabled objects so it's more like a true constructor, but if that would break too many legacy systems then add another function that gets called before Awake and gets called on disabled object.

Comments (6)

  1. 0097e1b88719b9cce9f3317a1a63899a?d=mm

    Altera

    Nov 19, 2018 04:35

    yes.
    really uncomfortable.

    unity are going a bad way. all korea major game company leves form unity3d.

    because Unity 3d looks like easy and flexible. But in real work, unity3d really uncomfortable and low graphic render quality.

    All major game company has gone and only Indie developer are using Unity.

    mecanim / MonoBehaviour / UI System : all Fail. too uncomfortable.

    i think unity's Start is easy but it is poor really bad select in korea.

    Some Say In Youtube Unity3d is enought to BAD GAME. just all.

    I agree too.

  2. 1128d21b41c5d4b5859c868331f54790?d=mm

    hongheng

    Sep 14, 2018 03:05

    Pls add this feature

  3. 2ea6221c4c3cea6a4aa1e71982a6eb57?d=mm

    darbotron

    Sep 11, 2018 13:51

    This is just one of many shortcomings of GameObject / Monobehaviour, but it's probably one of the most inconvenient.

    Sure, you *can* work around it but the workarounds tend to be very case specific (because of all the other init workarounds needed!) but bleurgh. I'm typically working on other people's for them as a contractor, and I've seen some very esoteric workarounds for what should be quite simple situations to handle.

    To prevent myself from having to deal with this in my own game I actually wrote my monobehaviour-alike base class which hooks into an actual main loop. This is managed by using 2 scripts (one with the lowest possible script priority, and another with the highest possible script priority) to hook into the standard Unity event functions at well defined times.

    Since the init / rest / loop / shutdown is all based on these two (never disabled) objects rather than relying on Unity to call the event functions this provides a nice and organised init / shutdown flow and objects can happily be initialised when not enabled.

  4. B2e90f13d40a6c7269563c744e594b86?d=mm

    krishnaanji

    Sep 09, 2018 05:35

    Yes, every programmer need this. Pls add this feature

  5. Dc4ef4894258111c6cc921b5f6b58354?d=mm

    misher

    Sep 03, 2018 12:25

    For your object, create a parent and move your script with all initialisation you need to it, and your visuals can be disabled in a children object.

  6. 9ca15108bfc01afbce78abe42edd3124?d=mm

    Hybrid-Dragon

    Jun 16, 2018 10:57

    Try calling the function in Awake() then disabling the object in Start() ? Awake happens before Start.

Your opinion counts

Help us make things better. Share your great idea for improving Unity or vote for other people’s.

Log in to post a new idea

Categories

All

(10750)

2D

(281)

Ads

(54)

AI & Navigation

(81)

Analytics

(130)

Animation

(395)

Asset Store

(355)

Asset Store Publisher

(15)

Assets

(543)

Audio

(184)

Cloud Build

(144)

Collaborate

(63)

Docs & Tutorials

(239)

Editor

(2507)

Everyplay

(17)

Game Performance Reporting

(21)

General

(978)

Graphics

(869)

GUI

(430)

Input

(172)

Licensing

(90)

Networking

(188)

Physics

(383)

Platforms

(440)

Profiling & Optimization

(84)

Runtime

(181)

Scripting

(1168)

Terrain

(170)

WebGL

(142)