Search Unity

Script getting disabled during Awake() due to error?

Discussion in 'Scripting' started by leftchannel, Feb 28, 2014.

  1. leftchannel

    leftchannel

    Joined:
    Feb 28, 2014
    Posts:
    25
    I recently came across a bizarre situation wherein:

    1) I had a script that was calling a function elsewhere in Awake(), but that function was throwing an exception

    2) When I started Play Mode, the editor gave no indication that an exception was thrown (nothing in console)

    3) The component in question (the one with the Awake() function) was disabled immediately beginning in Play Mode.

    I spun my wheels for nearly an hour trying to find out what script was disabling this script, and after narrowing it down to the script, I started commenting stuff out to find that the culprit was this one function call during Awake(), which was, it turns out, throwing an exception (the stuff it needed wouldn't be initialized until Start() ). Except I still NEVER SAW AN EXCEPTION, even though I was CERTAIN that one was being thrown.

    Summary: If an exception was thrown during Awake(), the behaviour would disable itself, and NOT display the exception in the Console.

    Is this expected behavior? If so, WHY?! And why is it documented nowhere?

    ....and if it's not expected behavior, I suppose I should file a bug report? :)
     
    Last edited: Feb 28, 2014
  2. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Never seen that before. I'm curious how you verified that an exception was being thrown when nothing came up in the console.
     
  3. leftchannel

    leftchannel

    Joined:
    Feb 28, 2014
    Posts:
    25
    It would've been accessing methods of a property that starts off as null. One of those things that can't *not* be an exception.

    Haven't had time to put together a reproducible test case that's not the entire project, on account of deadlines and such.
     
  4. kbth

    kbth

    Joined:
    Apr 19, 2017
    Posts:
    2
    Sorry to necro but I had the same type of thing happen today... It got fixed by moving the bulk from Awake to Start.... Still uncertain as to the exact cause.