Search Unity

Bug Console not updating values on Update?

Discussion in 'Editor & General Support' started by yosefstudios, Jan 21, 2021.

  1. yosefstudios

    yosefstudios

    Joined:
    May 8, 2015
    Posts:
    129
    So I came across this issue many times, and I never got to solve it because I honestly don't have any idea of what's causing it. Basically, the console is not updating values...let me explain a little bit:

    I was trying to make a simple health system for my game, and I created two simple methods:

    Code (CSharp):
    1. public void ReceiveDamage(int damageAmmount) {
    2.         health -= damageAmmount;
    3.  
    4.         if (health <= 0) {
    5.             health = 0;
    6.             Debug.LogError("You are dead!");
    7.         }
    8.     }
    And

    Code (CSharp):
    1. public void Heal(int restoreAmmount) {
    2.         health += restoreAmmount;
    3.  
    4.         if (health > 100) {
    5.             health = 100;
    6.         }
    7.     }
    So, in order to test it, I called some input functions on update (space to decrease health, r button to restore it) and debug.log the value. I first tested the decrease, which worked. But then, I tried to restore the health and...nothing happened, until it passed the health limit (100+, specifically 110). The health value was stuck at 60 until it changed to 110. Then I set up a limit (because I forgot it at the start xd), and as I expected, the health value got stuck again at x value.

    For some reason, something clicked on me, and I decided to now display the value on a UIText and...it worked. The value was actually changing all the time apparently, but for some reason, the console only decreased the value, but never increased it.

    So...is that a bug? I don't see why those methods that I used shouldn't work honestly.
     
  2. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    798
    Perhaps it'd be better to see all the code, but it appears you aren't debugging anything in your Heal function, so nothing would be written to the console.
     
    Joe-Censored likes this.
  3. yosefstudios

    yosefstudios

    Joined:
    May 8, 2015
    Posts:
    129
    The debugging is done in Update(), which should update the value every frame, therefore, any change too, isn't it?
     
  4. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    798
    Yep, that's why it's better if you show all your code, because in the code you have shared you are not debugging anything in the Heal function.
     
    Joe-Censored likes this.