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

Debug.Log in start gets triggered twice.

Discussion in 'Scripting' started by Username0101, Sep 30, 2015.

  1. Username0101

    Username0101

    Joined:
    Sep 3, 2015
    Posts:
    18
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class asteroidMove : MonoBehaviour {
    5.     Vector3 MoveTo;
    6.     float _currSide;
    7.     Vector3 _startPos;
    8.     GameObject Asteroid;
    9.     bool final = false;
    10.     int _sideStarter;
    11.  
    12.     void Start() {
    13.         _sideStarter = (transform.position.x == -200) ? 1000 : -200;
    14.         MoveTo = new Vector3 (_sideStarter, 0, Random.Range (-100, -700));
    15.  
    16.         Debug.Log(_sideStarter);
    17.         Debug.Break ();
    18.     }
    19.  
    20.     void FixedUpdate() {
    21.         if (final) {
    22.             Debug.Log ("Found! Going to: " + MoveTo);
    23.             Instantiate (new GameObject ("Going to"), MoveTo, Quaternion.identity);
    24.             Debug.Break ();
    25.         }
    26.     }
    27. }
    I've gathered that certain people who load their application have problems with that, and managed to fix it. But my "application" involves 0 LoadLevel instances. The Debug is triggered twice:
    -200
    UnityEngine.Debug:Log(Object)
    asteroidMove:Start() (at -----/asteroidMove.cs:16)

    Any grand ideas?
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,744
    Check to see if you have this script on 2 objects by accident.

    You can change it to Debug.Log(_sideStarter, this); Then click on each debug message. It'll flash-highlight each object the debug message came from.
     
    Aerrixus and Username0101 like this.
  3. Username0101

    Username0101

    Joined:
    Sep 3, 2015
    Posts:
    18
    Ah, indeed, there was a second object, also, this, so good to know that that exists. You couldn't just guess how often I would like to know which of the doofers sets off the info.

    Problemo fixo. (sorry Spanish, Latin and Italian people)
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,744
    I almost always add ', this' to my Debug.Log calls just out of habit. It never hurts to have a reference to where it came from, and occasionally it saves the day.
     
    Aerrixus likes this.
  5. Aerrixus

    Aerrixus

    Joined:
    Oct 17, 2020
    Posts:
    1
    bruh i just wasted 2 hours on understanding wtf is the problem and after reading your comment, i checked and found another object with the same script :D