Weird isue with Debug.Log i guess its a bug [Done and never mind]

So i got this litle Update function.

    void Update()
    {
        if (isDone == true && debugDone == false)
        {
            debugDone = true;
            Debug.Log ("done");
        }
    }

isDone is set to true after a thread finish his work debugDone is set to true in the Update function.
The weird thing is that he prints done 2 times but how can he do that after debugDone is set to true ?

I compiled it. It only came out with 1 “done”. Maybe you have another script telling you done?

Just tryed some thing else

    int count = 0;
    void Update()
    {
        if (isDone == true && debugDone == false)
        {
            debugDone = true;
            Debug.Log ("done");
            count ++;
        }
        if (debugDone == true)
            Debug.Log (count);
    }

is printing done, 1, done ,1 ,1 ,1…

i guess it have to do with setting isDone true from a thread. I also need to to do some Debug.DrawLine just wondering now if he will draw every thing 2 times…

Ok after i tryed to reproduce it with a new script

this gives no double debug

    bool isDone = false;
    bool debugDone = false;

    System.Threading.Thread thread;
    void Start ()
    {
        thread = new System.Threading.Thread (new ThreadStart (UslessFunction));
        thread.Start ();
    }
   
    // Update is called once per frame
    void Update ()
    {
        if (isDone == true && debugDone == false)
        {
            debugDone = true;
            Debug.Log ("isDone");
        }
    }

    void UslessFunction()
    {
        System.Random random = new System.Random ();
        double rndNumber = 0;
        while (rndNumber < 0.99d)
        {
            rndNumber = random.NextDouble();
        }
        isDone = true;
    }

I realised that after a Unity crash my backup game object was set back to active resulting in the script running on two game objects…:roll_eyes:

sorry for the trouble !!!

1 Like