Search Unity

Script named "Manager" runs without being attached to a game object?

Discussion in 'Scripting' started by Ruskul, May 1, 2018.

  1. Ruskul

    Ruskul

    Joined:
    Aug 7, 2014
    Posts:
    17
    Hello,

    It was my understanding that all monobehavior scripts had to be added to a game object in order to run. I recently created a script called "Manager" and it seems to be running automatically without being attached to any object. I put a debug.log line in Awake() and it gets called.

    Anyone know why this is?

    EDIT: I used debug.log(gameobject) as suggested by gorbit99. It did indeed reveal that the script was actually attached to a game object.
     
    Last edited: May 1, 2018
  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,175
    Try Debug.Log(gameObject)
     
    Ruskul likes this.
  3. Ruskul

    Ruskul

    Joined:
    Aug 7, 2014
    Posts:
    17
    That was a good idea. But, the results are weird. It says that the script is attached to a game object (canvas sprite) called "menu Title". The script however is not actually attached to it. At all. Both at runtime and in the editor, there no components attached to "Menu Title" apart from the default ones that come with it.
     
  4. Ruskul

    Ruskul

    Joined:
    Aug 7, 2014
    Posts:
    17
    Okay, The results are in. I'm an idiot. I had two objects, named almost exactly the same. A one MenuTitle had the script attached by me some time ago for testing purposes. Sorry for the dumb question... >.>
     
  5. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    4,754
    If you do Debug.Log(gameObject, gameObject); The first param is simply a string, in this case it prints out the object name. The second param will make the gameObject highlight in your scene hierarchy. Can help you track this down easier.
     
  6. Ruskul

    Ruskul

    Joined:
    Aug 7, 2014
    Posts:
    17
    Thanks, I didn't realize you could do that.