Do not use "var" in project which supposed to be a project for showcase and learning

There is "var" everywhere in the code of this FPS Sample.
Maybe "var" is easy to write, but the fact is - it is a pure evil if you want to read a code.
"var" it is "write and forget", which is not suitable for projects for learning.

Just look at any official Unity tutorial
For example this
"var" is never used in any tutorial.

So if this FPS sample designed for learning, I recommend to replace all "var" with proper variable type and stop using "var" in the future development of this project.


The FPS Sample tutorial is for fairly advanced learners who can deal with all those “var”. :slight_smile:


I just finished skimming through a code file picked at random (linked below) and I didn’t see any situation where they used it in a way that isn’t immediately obvious what the type for the variable is. Furthermore every situation the variables were used in were temporary. Any and every long term variable has its type specified.

I’m not a fan of using “var” but I don’t see any problems with the way it’s being used.

All of the tutorials at the links you provided are intended to be used by beginners. This project is not a beginner project by any stretch of the imagination and it’s not a tutorial either. I wish they hadn’t added it to the Getting Started section of the forum because it’s simply too difficult a topic for the people normally asking for help in that section.


No matter how advanced developer is. "var" makes code harder to read for everyone. This is a fact.
What a reason to make a learning process more complex?

There is a reasons why "var" never used in official Unity tutorials on the link above. It is sad to see that Unity started to violate its own rules. A rules which makes the Unity great, such as "easy to learn".

Another sad fact, it is how many people thinking that it is absolutely normal.
If someone thinking that I am a hater - this is not correct. On the contrary, I am love Unity, this is why I am worrying about it.

1 Like

I remember another discussion about var where people said about the same things and I remember posting that image that can be found on the documentation page, scripting section:

It seems that the use of var is very commonly accepted by professionals and the FPS Sample project is aimed at people who are experienced; it's not a tutorial like @Ryiah said.

1 Like

No, this is just your opinion. Just do a search for “C# var readability” and you’ll come across many arguments both for and against it including from individuals on these forums like @AndersMalmgren . It’s very much subjective and dependent on the way you learned C# and your experience with it as to whether it improves or hinders readability.

Yes, there are reasons why it was never used in official tutorials, but said reasons might not be for the reasons you seem to believe. One very easy reason is that Unity hasn’t always supported the keyword. I don’t remember exactly when supported was added, but it was definitely added sometime after I started using Unity.

Additionally, like I mentioned earlier, it’s use is very much subjective. Some people love it and some people hate it. Just because the person who wrote the tutorials didn’t use it doesn’t mean that the company had a policy against its use. If anything we know they don’t have a policy against it thanks to the picture linked by @ .

Finally, the “var” keyword has quirks in its usage that can be confusing to a beginner and thus leaving it out of beginner tutorials makes sense. Leaving it out of more advanced material doesn’t necessarily make sense. If someone can’t understand how to use it by that point they definitely are way over their head with this sample project.

Anything the devs want to do that saves them time so they can spend more of it on pure gold like this sample project is fine by me.

This is a really good point. We moved the sticky thread now. Hope it does not cause too much confusion but I think we were actively misleading people about the nature of the project with the current location. So better get it over with :slight_smile:

  • peter