Search Unity

Question Unity Hub Freezes runtime

Discussion in 'Scripting' started by SomeoneNameless, Jan 30, 2022.

  1. SomeoneNameless

    SomeoneNameless

    Joined:
    Dec 19, 2021
    Posts:
    2
    I am just learning Unity. I am scripting for my objective. After certain frames, the Unity Hub freezes and it does not get resolved even after waiting for half an hour. There was no problem until I added a for loop of a maximum of 25 iterations ( or a little bit more ). But after that, the Unity Hub keeps on freezing and not even on the loop ! anywhere ! even places that run fine without this new addition !

    I wonder if it is a problem with my settings. I am aiming for android platform. I use only one rigidbody and a few colliders that are simply square or circle. The program I am referring to is about 400 lines ( I have other scripts too but I unchecked them so that only this could run ). Could that be a problem ? What could be the problem and what could be done for the rectification ? Even if there is a way I could know where my code goes wrong ( if at all ), it would be of much help. I will attach some resemblance to the problem :

    private void some_function()
    {
    Debug.Log("There is a problem");
    }
    ^--- work fine
    ---------------------------------------------------------
    private void some_function()
    {
    Debug.Log("There is a problem");
    for(byte i=a_certain_variable;i>=0;i--)
    {
    Debug.Log(i);
    }
    }
    ^--- freezes after sometime

    I need to mention that the variable defining range of the for loop is not any trouble and other functions that use this same variable is working fine. It normally has a range of less than 25 but might go a little bit upwards.
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,492
    I don't see what this has to do with the Unity Hub. Moving this to the scripting forums.

    Any freeze will be you entering an infinite loop.
     
  3. Last edited by a moderator: Jan 30, 2022
    Bunny83 likes this.
  4. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    4,002
    Exactly. In most cases people do not really think about what datatype they are using. However you should be aware of signed and unsigned types, especially when doing such reverse loops which rely on the variable to become negative which it never can.

    ps:
    Personally I would never use "i" for any other type than "integer" because using such default patterns can easily fail with something other than an integer. I would guess that about 95% of programmers would expect that variable names "i", "n" or "k" to be integers. Variables named "b" to be most likely a boolean or a byte and variables named "f" to be a float or also a boolean flag. Though a lot things depends on context. Nothing is set in stone. What I would recommend is, from time to time, to think about all those patterns we use on a daily basis, what they actually do and why they work. Because sooner or later you come across someone who thinks he can improve the code by using a byte instead of an int and suddenly everything breaks :)