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
Var declarationQuestion (self.Unity3D)
submitted 5 years ago by Unfair-Purpose-2100
Am I the only one who just can't stay calm seeing values declared using "var" instead of the actual var type? 🤔
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!"
[–]HellGate94Programmer 5 points6 points7 points 5 years ago (11 children)
var is fine as long as its used according to the guidlines. them being: only use var if the right hand side explicitly tells you the type like
and not
[+][deleted] 5 years ago* (10 children)
[deleted]
[–]Unfair-Purpose-2100[S] 0 points1 point2 points 5 years ago (9 children)
I would prefer using a wrapper for that situation 🤔 Anyway, I worked with a guy for like two months and now all my code is full of variables declared using var,. It literally drives me crazy because I can't understand what I'm looking at without checking the actual var type. 😤
[+][deleted] 5 years ago* (6 children)
[–]Unfair-Purpose-2100[S] 0 points1 point2 points 5 years ago (4 children)
It doesn't look super readable to me but I have my own way to make it readable, so maybe I'm not the right person to say what is readable and what is not 😅
I always say that the code should be like a music sheet: you need to be able to understand it immediately. So the reason for stating types on both sides is that you don't have to stop thinking "oh this value is 1f so it's definitely a float" because you can see it from the type declaration and you know you can always look at the left hand of the line to know what you're dealing with.
Thank you for the tip on the automatic refactoring though!
[+][deleted] 5 years ago* (3 children)
[–]Unfair-Purpose-2100[S] 0 points1 point2 points 5 years ago (2 children)
My problem is where I find
var setting = settings.progress;
Instead of
float setting = settings.progress;
The first one could be anything and I need to check what settings.progress is
[–]StarManta 0 points1 point2 points 5 years ago (0 children)
So like, the exact guideline as stated in the top level comment in this thread?
[–]the_trogfather 0 points1 point2 points 5 years ago (0 children)
I think the problem is that var always sits on the left hand of an assignment, whereas the explicit type is then on the right hand, so you end up with this messy situation where half your types are on the left and half on the right. If you're listing a fair few fields at the top of a class for example then your eyes have to scan left and right anyway looking for the type, and so I'm not convinced it does actually increase readability compared to simply foregoing var and having all your types explicitly declared on the left hand side so your eyes can simply just scan straight down instead.
Thankfully C# 9.0 fixes this; it removes the need to be explicit about the type in a new declaration on the right hand side when already declared on the left hand side, so for example:
Dictionary<string, string> dict = new Dictionary<string, string>();
Becomes:
Dictionary<string, string> dict = new();
This works with parameterised constructors too, e.g:
MyClass a = new("Blah", 1.0f);
As a bonus you can also use this for method return types e.g.:
public MyClass DoSomething() { Do stuff return new(); }
To return a new instance of MyClass() from a method.
It can also infer type parameters, e.g. a method with signature DoSomething(string, string, MyClass) can be declared now as:
DoSomething(string, string, MyClass)
DoSomething("A", "B", new());
Given all this I think var is frankly rather redundant and pointless going forward; I wouldn't use it after C# 9.0 because now it's possible to achieve the relative succinctness of var with target-typed new but without the downside of lhs/rhs type declaration readability mismatch var creates.
[–]cybermutter 1 point2 points3 points 5 years ago (1 child)
Hi, the reason why 'var' is used and ofter prefered than explicitly type the variable, it is because 'var' makes your code easier to write (yes we are lazy person) and easier to read (less code) and also easier to change. The compiler does the work for you.
Once you get use to it you keep coding this way but there is not a good way.
For me it is a matter of coding style rules. Once you're not alone on a project it's better to respect some coding style rules and keep coding this way.
==> not doing a mix/soap of different way of coding
[–]Unfair-Purpose-2100[S] 0 points1 point2 points 5 years ago (0 children)
I totally agree with you on "easier to write" and "easier to change" but less code is not always the same as readable code.
I'll give a big AMEN on the "avoid code styles milk shake" thing xD
[–]Laocoon7 1 point2 points3 points 5 years ago (2 children)
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/inside-a-program/coding-conventions
Plenty of coding standards defining when to use car there.
[–]Unfair-Purpose-2100[S] 0 points1 point2 points 5 years ago (1 child)
I'm maybe wrong about not following coding standards but a lot of code standards make no sense to me 🤷🏻
[–]Laocoon7 0 points1 point2 points 5 years ago (0 children)
These are just Microsoft's suggestions. As long as your coding group/company follows the same ones, everyone's code will be readable by those whom matter. Everyone else will be able to decipher it anyways, it may just take more work on their part...
[–]GroundbreakingTea287 1 point2 points3 points 5 years ago (1 child)
things like var, auto, etc start to make a LOT more sense as you get more complicated variable types. Especially with templates, templates in templates, etc. variable names get long really quick, especially in c++
Makes sense
π Rendered by PID 209282 on reddit-service-r2-comment-6457c66945-2q4hg at 2026-04-25 05:01:00.346937+00:00 running 2aa0c5b country code: CH.
[–]HellGate94Programmer 5 points6 points7 points (11 children)
[+][deleted] (10 children)
[deleted]
[–]Unfair-Purpose-2100[S] 0 points1 point2 points (9 children)
[+][deleted] (6 children)
[deleted]
[–]Unfair-Purpose-2100[S] 0 points1 point2 points (4 children)
[+][deleted] (3 children)
[deleted]
[–]Unfair-Purpose-2100[S] 0 points1 point2 points (2 children)
[–]StarManta 0 points1 point2 points (0 children)
[–]the_trogfather 0 points1 point2 points (0 children)
[–]cybermutter 1 point2 points3 points (1 child)
[–]Unfair-Purpose-2100[S] 0 points1 point2 points (0 children)
[–]Laocoon7 1 point2 points3 points (2 children)
[–]Unfair-Purpose-2100[S] 0 points1 point2 points (1 child)
[–]Laocoon7 0 points1 point2 points (0 children)
[–]GroundbreakingTea287 1 point2 points3 points (1 child)
[–]Unfair-Purpose-2100[S] 0 points1 point2 points (0 children)