Help finding cause of freeze

Hi all,

After days of trying I’ve almost given up trying to find the cause of a freeze i’m getting. During execution of a game the editor will freeze at random. Sometimes it takes 5 minutes, sometimes it takes an hour, but it always happens.

I have tried attaching monodevelop to the Unity Editor before and after the freeze. However monodevelop will not pause the application once the editor is frozen. I have bought and install an asset called PanicButton with is meant to stop out of control loops and the like, however this also did not work.

Interestingly when the editor does freeze it isn’t shown as “Not Responding” and it’s still runs in task manager as normal.

The game will also freeze when built.

Does anyone have any other things I can try?

Cheers!

Are you sure you don’t have any infinite loops anywhere? That’s what causes my freezes 99% of the time. Try to find a particular spot or action you do to cause the freeze to help narrow down the source of the problem.

An infinite loop was my first thought, as I do use them. However, I never use them without a yield. The PanicButton asset is also designed to recover from freezes caused by that exact problem, but once Unity freezes in my case, that asset does not work.

Can an infinite while loop with a yield cause such a freeze?

If you attached md, why not use the debugger? Just increment some variables in suspicious places and watch their count in the debugger.

But how will i tell the part that’s bad when Unity freezes?

I don’t know how big your code base is. If it’s only a few places (that could be responsible for the infinite loop), I would just in each place increment a different variable and look at all of them in the debugger. There are possibly better ways but this works good enough.

Haven’t found the exact problem yet, but i have isolated it to the script where i control navmesh agents. No loops exist in there and the main function is to find assign paths to the agents.

You guys know of anything relating to nav agents that might cause a freeze?

Perhaps it’s the “finding assign paths to agents”. Also, when Unity freezes, go to the Task Manager (or the MacOS equivalent if you use a Mac) and look at Unity for a few seconds. Does the RAM or CPU usage grow? When I write an infinite loop, the RAM seems to grow forever while Unity is freezing.

RAM and CPU act like nothing is happening.

Sorry, what i meant is that this script mainly just assigns paths to agents. There are probably about 40 agents.

I’m completely stuck.

Using
nav.Warp(location);

Instead of

NavMeshHit hit;
if(NavMesh.SamplePosition(newVector, out hit, 2, NavMesh.AllAreas))
    nav.SetDestination(hit.position);

Seems to fix the freeze as far as I know. But I have no idea why.