Historically, one of the taboo constructs in Unity3D was the use of c# foreach block because each iteration of the loop would consume a few bytes of data uncessarily.
Curious if that's still the case on modern releases?
My Googling and (very rudimentary) testing is coming up with non-conclusive results and I'd like to leach off of someone else's knowledge here rather than dive into low-level benchmarking myself. :-)
Has anyone poked at this recently to determine if it's still necessary to avoid foreach in Unity3D?
No, foreach
is no longer bad in 'modern' unity but the fix is not yet fully released.
It was first fixed on a special build Unity Patch 5.3.5p8 on early July, which you can get from here. This is a special Edition you must get to receive that fix.
Now, Unity upgraded their compiler to Mono 4.4 on Unity 5.5 beta release which is not yet final release. It fixed the foreach
problem. Once this version is released in the coming months, foreach
memory allocation will be a thing of the past. You can still download for testing purposes but don't release a game with a beta build.
Scripting: Upgrade C# compiler to Mono 4.4. The new compiler still targets C# 4 and .Net 3.5, but provides better performance and many bug fixes.
It is now fixed but the fix is still in beta mode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With