- Home /
Hunting for gamecrashing bug, does disabling game objects and scripts mean they don't affect the game anymore?
I've got a scene I've been working on for a few weeks, and it's been working fine the whole time. Today I added a health bar GUITexture and a script that corelates the health bar to the unit's current health... pretty straightforward. Ever since I added it, my game runs for about 2 mins, during which time the CPU fans slowly get louder and louder, and eventually the game crashes.
I've tried turning off the health bar object, disabling the script, even going into the script and commenting out the whole thing. When that didn't get rid of the issue, I tried disabling every object in my scene except for the main camera, but the same thing keeps happening. After I close Unity, the CPU fans go back to a quiet speed, and it's not until I open Unity and then run the game for a few minutes that the crash happens.
With a complex scene I've spent so much time working on, I hate to scrap it and start over on a new scene. Anybody have any tips?
Did you look at statistics to see if some specific number are constantly going up? You can enable statistics by clicking at Stats text button in top right corner of game window.
Also, maybe any of your script does some work in editor? Try opening project with your scene, don't run the game and wait a moment to see if the same thing happens.
Yeah, the FPS s$$anonymous$$dily drops from about 70 to about 13 over the span of a few $$anonymous$$utes, until finally unity just puts up a crash prompt and it's game over. If I don't run the game at all, everything is fine, it's just when it's in play mode.
Sounds like you have an Instantiate call running every frame in an Update method somewhere... or something similar.
That's what I thought too, but looking at the editor there aren't any new objects being added to the scene. I've watched the stats, there aren't any sudden changes in draw calls, or anything like that. What's weird is, I'm testing it again right now but with the profiler on, and I can't find any s$$anonymous$$dily increasing quantity in the background processes. Every so often, the "Overhead" bar spikes way up there, sinking the game to 15 fps, but it's only for an instant. I'm fairly positive it's a complex enough issue that without sending my whole project to everyone who had an idea of where to look, I probably won't be able to give enough info via description to be of any help to you guys. This may just be a long tedious process of deleting parts of my scene til I find the bug.
If the problem first occurred after having implemented the health bar, that's a pretty good place to start. Good luck.
Answer by growling_egg · Sep 14, 2013 at 03:49 AM
I'm usually a pretty firm believer in writing one's own code, and today I realized why. The thing that was causing all this mischief for me was a script I copy/pasted from an official Unity sample page regarding how to make a GUITexture follow a Game Object around the screen (as a health bar might be expected to do in an RTS). When I deleted Unity's version and wrote my own (albeit pretty similar) version, viola, no crashing, and the game is back up to 80 fps. Lesson learned, folks.
Rolling my own has not only always worked for me, it is also the reason that I know it will keep working for me in the future.