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

Constructor works two times

Discussion in 'Scripting' started by JPCannon, Dec 3, 2014.

  1. JPCannon

    JPCannon

    Joined:
    Sep 25, 2013
    Posts:
    37
    I have One class in script. script is only in one object on scene. But when i write Debug.Log in it constructor it works two times. One i have info that it is from my Debuger, and second is simply debug value. What`s wrong?
     
  2. Sbizz

    Sbizz

    Joined:
    Oct 2, 2014
    Posts:
    250
    If you don't give us your code, I have no idea how we can help you.
     
  3. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    Can't tell without code. But you do know you can't use the object contrustor if your class is derived from monobehaviour, you will have to use the Awake() or Start() methods instead.
     
    JPCannon likes this.
  4. RockoDyne

    RockoDyne

    Joined:
    Apr 10, 2014
    Posts:
    2,234
    I would say first search for that component in the scene hierarchy. If you didn't screw up your code, chances are you have two instances of that component in the scene.
     
  5. JPCannon

    JPCannon

    Joined:
    Sep 25, 2013
    Posts:
    37
    My wrong that i use constructor thx