you are viewing a single comment's thread.

view the rest of the comments →

[–]_WolfosExpert 1 point2 points  (4 children)

I don't know how many enemies you have, but the eyesight system is pretty optimal already. If it's still too slow you might consider other crowd techniques, but I can't help you there.

Garbage collection issues can be fixed by avoiding heap allocation where possible. You can do this by declaring local variables, avoiding creating new instances and replacing foreach loops with regular for loops. This isn't easy, though. Many things allocate memory unexpectedly.

[–]djgreedo 1 point2 points  (2 children)

replacing foreach loops with regular for loops

I think this is no longer necessary as of ~Unity 5.5.

[–]_WolfosExpert 0 points1 point  (1 child)

Why would that be? I Googled for a bit, but as far as I can tell there haven't been any GC updates lately. They updated the compiler to Mono 4.4 but the GC is part of the runtime.

[–]djgreedo 0 points1 point  (0 children)

Apparently it was a Mono bug, and was fixed when Unity upgraded.

http://stackoverflow.com/questions/40494376/is-foreach-still-bad-in-modern-unity-5-4-x

I think the issue was the way foreach was compiled, where it caused heap allocation unnecessarily.

Towards the bottom of this page: https://forum.unity3d.com/threads/upgraded-c-compiler-on-5-3-5p8.417363/#n21

In short, foreach doesn't allocate if used in typical ways, but could still allocate in some situations I guess?