Ok well this is only a recent problem, It may have only started when I upgraded to the newest version of unity or it (more likely) is some problem I’ve made between now and then.
Basically the games runs at around 50fps normally. However around 3/4 times per level it’ll just freeze for around a second and then return to normal. I’m just wondering if anyone else has had that problem or knows of anything that could cause it. I’ve tried it on both Windows and Max OSX (I’m using a dual boot mac book pro).
Also I should point out I’m actually more knowledgeable about on the business side and art side so if you could keep replies as “simple” as possible I’d appreciate it :).
Yes, I experience this too, both in my own projects and other people’s, although the freezes are often much shorter than a second, but still noticeable.
You would have to profile it to know for sure. It could be the graphics card for the first time touching a specific texture for an object that just became visible. Or it could be the GarbageCollector. But in that case the pause is much much shorter.
You can reduce GC hiccups by simply allocating less memory. Generally you should try to avoid allocating a lot of memory on a per frame basis.
Ok sorry, how would I “avoid allocating a lot of memory on a per frame basis”?
Yeah mine seem to vary, some are only just noticeable, and others last up to a second. Basically though I’m showing the game to some big local studios in a few days and I’m just trying to “work out the kinks”.
Are you using highest settings and high res textures?
If so try a lower quality setting, perhaps you just flood your VRAM and enforce uploads every few frames as the card is not capable to hold all the data all the time
At the moment textures are on full, hard shadows only, 2 pixel lights. I don’t think it is due to the quality settings as it has worked fine before, this is just a recently emerging problem.
How would I: “perhaps you just flood your VRAM and enforce uploads every few frames as the card is not capable to hold all the data all the time”?
Edit: I’ve just tested it on half res textures and quarter res and still get small freezes occasionally.
I think one of the things Joe is talking about with regard to memory allocation is to avoid instantiating a lot of objects in the same frame.
So, for example, if you hit a zone that spawns a bunch of enemies, if they are all created in the same frame, that will cause the game to freeze up as it does all that before it can go in.
Another example would be creating a lot of particles under program control all at once.
The thing to do is to use co-routines to create things so that process can take place over several frames and not hold up the show.
Profiling is also mandatory to determine your overall performance bottlenecks, such as raycasting, mesh rendering, physics, etc.
Install the Apple Developer Tools, build your game with debug symbols included, and then run your game and Shark at the same time.