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

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

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 :confused:

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.

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.

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.

    public float GetFishPerSec()
    {
        float tick = 0;
        foreach(float item in tickValue)
        {
            tick += idleCount[0] * tickValue[0];
        }
        return tick;   
    }

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

saying item is assigned but never used

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.

1 Like

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?

cant see a problem there, how many items in that list ? and how often u call that function ?

public float[] tickValue = new float[6];
    public float[] idleCost = new float[6];
    public float[] idleCount = new float[6];

those are the arrays,

public float GetFishPerSec()
    {
        float tick = 0;
        foreach(float item in tickValue)
        {
            tick += idleCount[0] * tickValue[0];
        }
        return tick;   
    }





    public void AutoFishPerSec()
    {
        fish += GetFishPerSec () / 10;
    }


    IEnumerator AutoTick()
    {
        while (true)
        {
            AutoFishPerSec();
            yield return new WaitForSeconds(0.10f);
        }
    }

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

on void start i start the autotick coroutine

I have no idea what is the purpose of your code, the warning just saying u declared something that u didnt use.

U can remove the While loop

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

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

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;

1 Like

cool, thank you for the help appreciate that.