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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

c# script attached to empty game object

Discussion in 'Getting Started' started by jimi141, May 3, 2023.

  1. jimi141

    jimi141

    Joined:
    May 27, 2021
    Posts:
    5
    I have a scene with a number of objects and one is empty to which I've attached a script. The script is not attached to any other object and there are no other references to this empty object or script anywhere. When I play the game, however, the script executes. I don't understand why. I'm fairly new to this so I've probably missed something but I would appreciate it if somebody could put me straight here as to why this is happening.
     
  2. BABIA_GameStudio

    BABIA_GameStudio

    Joined:
    Mar 31, 2020
    Posts:
    491
    If you put a gameobject into a scene and it has a script attached, it will run the script. It doesn't matter if you created the gameobject as empty or not.
     
  3. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,182
    If you've attached a script to it then it isn't empty. GameObjects are only truly empty when they have nothing attached to them (ignoring the transform component which is automatically added and can't be removed).
     
  4. jimi141

    jimi141

    Joined:
    May 27, 2021
    Posts:
    5
    Th
    Thank you. This I didn't know. I thought I needed some kind of trigger on the object. Thanks for putting me straight.
     
  5. jimi141

    jimi141

    Joined:
    May 27, 2021
    Posts:
    5
    Thank you for response. I'm wiser now.