May 7, 2014 by Nikos
One of the most frequent tidbits of advice you can find on the internet about Unity3D is to not use LINQ expressions in the game. I can understand how LINQ can be performance heavy but on the other hand it can be incredibly useful when building editor tools. Granted you must always strive to write efficient code but sometimes the trade off is a lot better.
For example some times you have to manipulate the scenes somehow and you have to gather specific objects to perform a modification but that set being in a densely populated scene might be more than enough to be a pain for manual selection. Depending on the situation you can do something as simple as GameObject.FindGameObjectsWithTag and it’ll be enough.But sometimes you want a smaller set of objects with the same tag. You can either write a loop of any kind and try to distinguish which objects you want or you can use a LINQ expression of one line.
Since LINQ has an SQL-esque syntax it will be easy for someone with SQL experience to use it for creating subsets of lists very easily.Subsets that you’d normally need nested loops and if-statements to create.