Search Unity

why does unity now freeze solid when i hit play to test my game?

Discussion in 'Getting Started' started by Sylvir, May 3, 2015.

  1. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    i double checked before trying again that there are no compiler errors, and no script or coding errors but last night unity just started to lock frozen on me anytime i try to hit play to test play my game. I can do anything else eddit scripts change the scene and so on no issue whatsever. for some reason now its started to lock up and ih ave to control alt delete to close it it wont let me do anything once i try to test play. has anyone else had a similar issue to this or have any idea how i might go about fixing it? the only other soulution i can come up with is uninstalling unity then re downloading it and importing my project folder. I would prefer not having to do that though.. any thoughts? thanks
     
  2. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    I am going to swap my project folder over to my laptop and see if it has the same error in unity on there. if not, then i guess ill have to reinstall unity. may as well sence there is an update as well. If it still doesn't work on my laptop either then it must be something in my project that went corrupt :/
     
  3. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    broke in the laptop unity too.. hmm.. do i need to update to the new version of unity is that possibly why its breaking now?

    I have found in some reasaerching more that version 4.6 sometimes had a bug when something that was undefined (a yellow flag error) could cause a lock up on play testing. I found that there is something missing definition on my code. So I am looking up how to define that item im missing to see if that is whats wrong.

    I am responding on here to explain what i found and what it might be just in case another person in the forums starts up and runs into this issue as well.

    Ill edit in a bit and let this post know if i got it working again or not.
     
    Last edited: May 3, 2015
  4. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    223
    Disable all scripts, no syntax error doesnt means no logic error. A single non stop while loop(or for loop that increase then decrease the counter do the same) will make your unity freeze.
     
  5. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    Thanks, i have commented out the part i thought was wrong, and this is what it is its a foreach loop. saying that items is not defined, but i thought that it was.. this is the code.

    Code (CSharp):
    1.     public float GetFishPerSec()
    2.     {
    3.         float tick = 0;
    4.         foreach(float item in tickValue)
    5.         {
    6.             tick += idleCount[0] * tickValue[0];
    7.         }
    8.         return tick;  
    9.     }
    10.  
    saying it has the issue with the word item being used but never defined. I guess i miss understood foreach loops and arrays, i thought that the word item was a key word that you use that means for each one in the array [0] [1] and so on
     
  6. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    saying item is assigned but never used
     
  7. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    223
    We are trying to check if your Unity program is dead or your code got problem, unless u are 100% certain that you will never make such mistake, disable all of your script would be a smarter choice. If the program still hang even u disable all of them, then there is nothing much u can do about it, if it doesn't hang, turn on 1 script at a time until it hang again, then troubleshoot that script.
     
    Sylvir likes this.
  8. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    Thank you @narf03 I went through that and found out that it was the gamecontrol script, specificly that foreachloop that is hanging it up, when that loop is disabled then the game will run in the test view. Do you know what would look wrong with the foreachloop that i posted above?
     
  9. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    223
    cant see a problem there, how many items in that list ? and how often u call that function ?
     
  10. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    Code (CSharp):
    1. public float[] tickValue = new float[6];
    2.     public float[] idleCost = new float[6];
    3.     public float[] idleCount = new float[6];
    those are the arrays,

    Code (CSharp):
    1. public float GetFishPerSec()
    2.     {
    3.         float tick = 0;
    4.         foreach(float item in tickValue)
    5.         {
    6.             tick += idleCount[0] * tickValue[0];
    7.         }
    8.         return tick;  
    9.     }
    10.  
    11.  
    12.  
    13.  
    14.  
    15.     public void AutoFishPerSec()
    16.     {
    17.         fish += GetFishPerSec () / 10;
    18.     }
    19.  
    20.  
    21.     IEnumerator AutoTick()
    22.     {
    23.         while (true)
    24.         {
    25.             AutoFishPerSec();
    26.             yield return new WaitForSeconds(0.10f);
    27.         }
    28.     }
    29.  
    there is the rest of the code that i have set up to use with it. its saying that "
    Assets/_Scripts/GameControl.cs(155,31): warning CS0219: The variable `item' is assigned but its value is never used"

    as the yellow error flag, that is for some reason freezing my unity program on test play
     
  11. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    on void start i start the autotick coroutine
     
  12. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    223
    I have no idea what is the purpose of your code, the warning just saying u declared something that u didnt use.
     
  13. narf03

    narf03

    Joined:
    Aug 11, 2014
    Posts:
    223
    U can remove the While loop

    IEnumerator AutoTick(){
    AutoFishPerSec();
    yield return new WaitForSeconds(0.10f);
    StartCoroutine(AutoTick());
    }
     
  14. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    Thanks, i think that for some reason it was saying my error was the word item and showing the yellow flag, nothing else was showing up under errors. it looks like i was trying to calculate numbers higher then floats will handle though so it locked. I need to look up how i can store a larger number then floats will go i guess lol
     
  15. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    It's saying that item is never used because it is never used. The line 6

    tick += idleCount[0]* tickValue[0];


    should be

    tick += idleCount[0]* item;
     
    Sylvir likes this.
  16. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    cool, thank you for the help appreciate that.