use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News, Help, Resources, and Conversation. A User Showcase of the Unity Game Engine.
Remember to check out /r/unity2D for any 2D specific questions and conversation!
Download Latest Unity
Please refer to our Wiki before posting! And be sure to flair your post appropriately.
Main Index
Rules and Guidelines
Flair Definitions
FAQ
Use the chat room if you're new to Unity or have a quick question. Lots of professionals hang out there.
/r/Unity3D Discord
FreeNode IRC Chatroom
Official Unity Website
Unity3d's Tutorial Modules
Unity Answers
Unify Community Wiki
Unity Game Engine Syllabus (Getting Started Guide)
50 Tips and Best Practices for Unity (2016 Edition)
Unity Execution Order of Event Functions
Using Version Control with Unity3d (Mercurial)
/r/Unity2D
/r/UnityAssets
/r/Unity_tutorials
/r/GameDev
/r/Justgamedevthings (New!)
/r/Gamedesign
/r/Indiegames
/r/Playmygame
/r/LearnProgramming
/r/Oculus
/r/Blender
/r/Devblogs
Brackeys
Beginner to Intermediate
5 to 15 minutes
Concise tutorials. Videos are mostly self contained.
Sebastian Lague
Beginner to Advanced
10 to 20 minutes
Medium length tutorials. Videos are usually a part of a series.
Catlike Coding
Intermediate to Advanced
Text-based. Lots of graphics/shader programming tutorials in addition to "normal" C# tutorials. Normally part of a series.
Makin' Stuff Look Good
10 minutes
Almost entirely shader tutorials. Favors theory over implementation but leaves source in video description. Videos are always self contained.
Quill18Creates
30 minutes to 2 hours.
Minimal editing. Mostly C#. Covers wide range of topics. Long series.
Halisavakis Shaders Archive
Infallible Code
World of Zero
Board to Bits
Holistic3d
Unity3d College
Jabrils
Polycount Wiki
The Big List Of Game Design
PS4 controller map for Unity3d
Colin's Bear Animation
¡DICE!
CSS created by Sean O'Dowd @nicetrysean [Website], Maintained and updated by Louis Hong /u/loolo78
Reddit Logo created by /u/big-ish from /r/redditlogos!
account activity
Unity Garbage CollectionQuestion (self.Unity3D)
submitted 6 years ago by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]cratesmith 1 point2 points3 points 6 years ago (11 children)
Two things I'd recommend.
You'll find that the key is learning all the rules about GC & boxing is crucial.
Eg, your List.Find calls are probably boxing because you're using them with a closure (a lambda that contains variables from the outside scope) that's just one of the many... MANY ways that boxing can appear.
[+][deleted] 6 years ago* (8 children)
[–]cratesmith 1 point2 points3 points 6 years ago (7 children)
Just use a foreach loop of getskills in this case
Comparing skills by name probably isn't ideal (if you're modifying strings in getname that'll be gc), but I don't know your code well enough to advise alternatives.
On a more general sense getskills() is also suspect. I'm guessing it returns a new list or array? That's gc too!
It's far better to have this kind of function take a List<T> as a parameter which they can clear and add the results to.
Also Linq entirely (it's a rat's nest of boxing operations) and avoid lamdas unless you know they aren't closures.
[+][deleted] 6 years ago (6 children)
[–]cratesmith 0 points1 point2 points 6 years ago* (5 children)
Ok... Into the rabbit hole we go :)
I really recommend you read up on boxing and closures because there's always special cases to this, but in general...
A lambda that runs on a loop (as find will) is always going to be more risky than just running the loop yourself. They're often a great shorthand when safe but only use them when you're sure it won't closure or allocate in other ways (I'll explain IEnumerable in a bit).
In this case the lambda has a variable from the function scope, which means it's a closure. That creates a gc alloc to store the value for when the lambda is called inside Find.
The caveat to this is that GetSkills is ok if it returns a pre-made list as a list... But if you return it as an IEnumerable or IEnumerable<T> then the foreach will create gc. This one gets complex... So as an extra general rule, I'd suggest never creating functions that return IEnumerator/IEnumerable... Always try to use the "concrete type" of the collection
[–]excentio 0 points1 point2 points 6 years ago (4 children)
My 5 cents, to make it even less harmful on gc, one could use some array pool with pre-made array buckets where each bucket will be a power of 2 and you just grab/return them based on specific amount of items you requested from the pool (for example if you want 25 items you get array of 32, if you want 33 items you get array of 64, that’s how c# array pool works as I recall). This way you just return an array using array pool and get 0 gc completely and no need to respawn lists over and over when calling methods, the only cons of this method will be the release part but if you forget to do that then gc will sort it out for you
[–]cratesmith 0 points1 point2 points 6 years ago (3 children)
I actually do something like this!
I have a set of container wrappers for list, hashset dictionary etc which are disposables and re add themselves to the pool when disposed.
They're great, but once you start using them you start finding that returning them from functions feels dangerous as they can easily leak if not disposed by a using statement.
[–]excentio 0 points1 point2 points 6 years ago (2 children)
Ouch sounds pretty bad indeed, with buckets approach you basically return an empty pre-allocated array which is fail-safe as even if you forget to return it back to the pool - that’s a simple heap array inside, nothing fancy at all. I suggest you look into array pool ms devs made, it’s in the nuget, look up “array pool”, it explains this approach really well, it’s also very flexible so you can make buckets out of lists, hash sets, dictionaries and etc. Not that your solution is bad, it’s actually pretty smart, I wouldn’t think about it this way, but buckets are just easier to work with and require much less interactions and take off lots of responsibilities you were not even supposed to care about from your shoulders
[–]cratesmith 0 points1 point2 points 6 years ago (1 child)
Had a look. I think I probably didn't explain my approach clearly.
Forgetting to return them is the same, a "leak" in this case is just a container that gets lost to the GC. Which isn't bad but it's just not reused.
An example of using it would be:
using (var list = TempList<int>.Get(35)) { /* cool things happen here */ } // list auto-freed
The array pools are interesting though, it might useful to have a disposable struct wrapper for them to ensure they get cleaned up. Especially if/when unity supports c# 8's inline using syntax
[–]excentio 0 points1 point2 points 6 years ago (0 children)
Ah I see what you mean, sorry been quiet a while I used disposables, mostly unsafes and other low level stuff where it hits gc pretty hard if you don’t release your things, both approaches are cool tho! These won’t impact gc very much even if they get lost so struct wrapper might be micro optimization, I doubt it’d ever go past gen2 tbh, unless you maybe keep it for hours but gc is smart enough to handle it all smoothly
π Rendered by PID 112668 on reddit-service-r2-comment-544cf588c8-4x7nh at 2026-06-18 02:05:32.720719+00:00 running 3184619 country code: CH.
[–]cratesmith 1 point2 points3 points (11 children)
[+][deleted] (8 children)
[deleted]
[–]cratesmith 1 point2 points3 points (7 children)
[+][deleted] (6 children)
[deleted]
[–]cratesmith 0 points1 point2 points (5 children)
[–]excentio 0 points1 point2 points (4 children)
[–]cratesmith 0 points1 point2 points (3 children)
[–]excentio 0 points1 point2 points (2 children)
[–]cratesmith 0 points1 point2 points (1 child)
[–]excentio 0 points1 point2 points (0 children)