Hi, I’m working on a semi 3-D game and was wondering if I can use all 3 or a combination to make things easier. I do have knowledge of the languages and I probably will end up using boo for my game but I do like using JS for my Ai’s(just a habit I never broke :p)
Just kidding. The performance is the same, no matter what language you use inside Unity. All three scripting languages gets compiled to a Unity internal language when you build your exe.
First of all the languages get compiled into CIL, or Common Intermediate Language. Which is a sort of high-level assembly style instruction set which is what Mono (that Unity runs on) and .NET takes as input to their JIT-compilers.
Secondly, performance is not the same between the languages. The compilers to not always produce the same output IL and it can in a lot of the cases cause slower performance on the less developed compilers (Boo, UnityScript). GMCS which is the C# compiler Unity uses (I think, it might me another version?) will in many cases produce better CIL instructions than Boo or UnityScript, leading to better performance in the end.
All in all, C# has better IDE support (Mono Develop or Visual Studio), has a better compiler, will let you do things the other languages can’t. Has more documentation (MSDN) and examples then any of the other two.
Lord I get tired of the C# language nazis appearing every time someone has the audacity to suggest using a language which isn’t C#.
There is no “clear #1 choice” since all 3 languages have their advantages and disadvantages. And FYI, there is an awful lot that Boo can do that C# can’t.
And there is no real world performance difference between any of the languages. This has been covered several times, and is in the Scripting FAQ above.
I don’t know much about programing, but common sense dictates that you’d want to stick to a language you know . Like it doesn’t make any sense to learn 3 languages at once, or code things in 3 different languages at once
It partly has to do with the fact that C#'s compiler is developed by a large, professional team, and Unityscript/Boo is developed by one guy. It’s very impressive and some of the advanced features in Boo are really cool, as he is without a doubt competing, but it’s still a sort of david and goliath with regards to resources available. And in this case goliath has a more tricks up it’s sleeve. JS is improving, with the recent removal of assigning unknown types to vars from JS helping avoid hidden reflection based assignment, but it’s not equal yet.
Also Unityscript/Boo’s more implicit nature can cause minor performance losses in some code paths. The less the compiler knows, the less optimizations the compiler can perform to speed it up.
And CIL is in no way a “Unity internal language”.
Although the differences would be so little, that I wouldn’t recommend choosing a Mono language for speed, but rather features and syntax.
To be honest I started with Javascript and found it as a mistake. As it is much better to start with C# as you’ll be using that more in more professional terms and jobs. Now of course switching from Unity Javascript to Unity C3 is extremely easy. All you need to know is a few new sytax things and change function to void. variables get more detailed but besides that C# is pretty close to Javascript in Unity.
Plus C# has lots of universal functions that you can use that are not just part of Unity. Sure javascript has them to but is allot harder to find good resources on the internet for javascript, as most of them are for web pages and not this kind of thing.
Therefore, I vote for C#, it really isn’t that hard compared to Java Script and it is much better just learning it from the start, saving the hassle for later.
If you know programming in all 3 languages, just take C#. It’s the best choise, since C# was developed for .NET (and Mono is the .NET Port) and it’s CIL code.
Second, there is little use of JavaScript or Python/Boo knowledge, because: UnityScript is not JavaScript. Most of the stuff (except some of the syntax) from JavaScript doesn’t work with UnityScript, because UnityScript uses the .NET/Mono library/Framework. Same goes for Boo.
The only situation where you could/should use UnityScript/Boo is, if the only language you ever knew was JavaScript or Phyton respectively, because of the similar syntax. If you don’t know any of the three languages, C# is the way to go too.
Edit:
Forgot to mention, that it’s not a good idea to mix C#, Boo and UnityScript in the same project. This may cause many problems with the execution orders, i.e. C# script can’t access UnityScript files unless you use some ugly hack, the compilation order is C# > UnityScript and you have to do some nasty hacks to compensate for this. If everything is written purely in C# or UnityScript, you won’t have this kind of problem
It’s not a bug, just not optimized. All three languages are similar in performance. Some constructs, like loops could be slower in UnityScript because the UnityScript compilers generates less optimized CIL code. Other things may be faster in UnityScript because they are optimized by the compiler, while if you do it in C# manually it may not be as optimized (that’s then somewhat of lack of the programmers skill).
That’s the only reason why someone should use Boo and UnityScript. However, someone who comes from JavaScript will still have to learn a bunch of stuff about the .NET/Mono Libraries, Classes etc. Because these don’t exist neither in JavaScript neither they do in Python. The only thing you don’t have to “relearn” is the sytanx and even this is not correct.
i.e. UniyScript has a concept of classes, polymorphism, and strong typing which isn’t common in JavaScript. So your knowledge of JavaScript is quite useless here anyway, especially when writing for mobile devices where strong typing is enforced.
Learning C# is 70% just learning the syntax. Polymorphism, interfaces, etc. that’s something you need to know in any of the three languages Unity3D offers. The remaining 30% are C# specific language features, like lambda, extensions, events/delegates.
C# is pretty easy language to learn. It’s on par (and even easier than) Java (not JavaScript) and with any decent book the basics can be learnt in less than 4 weeks. However, learning to write algorithms, solve problems etc., that kind of stuff is NOT LANGUAGE SPECIFIC. If you know how to make a procedural terrain generation in Python, you also know how to make it in C#. It just takes a few weeks learning the syntax. Problem solving remains same in every language.
Only for the new and mediocore developers. The more experienced and professional do use this features.
And that’s not true neither. There is dozen of examples, where you could do stuff in one single line in C# but would beed 5+ in UnityScript, sorting of arrays with Lambda and Linq extensions being one example.
public class Person {
public string Name;
public string Age;
}
List<Person> persons = new List<Person>();
...
// add 100 persons here, unsorted
...
persons = persons.OrderBy(p => p.Name).toList(); // sorted by name
persons = persons.OrderBy(p => p.Age).toList(); // sorted by age
There is just no way to make this any shorter in UnityScript. Also shorter doesn’t always means: better readable.
float fs= Mathf.Clamp(d.magnitude * d * Time.deltaTime * s, ms); // is shorter than
// Get final speed per second
float finalSpeed = direction.magnitude * direction * someVariable;
// Final speed per frame
finalSpeed *= Time.deltaTime;
// make sure final speed is within it's given limits
finalSpeed = Mathf.Clamp(finalSpeed, minSpeed, maxSpeed);
Clearly the second part is longer + commented, but it’s better code than the one above, even though it’s longer, it’s better maintainable especially if someone not familar with the code has to do some changes. So you maybe should stop spreading this “urban myths”.
That’s some outdated paradigm which ruby and pyhton attempted (to keep code short), which results in unreadable code and horrible fore-/backward compatibility. If I have a .NET 2.0 application, I can be sure it will work on 3.5, 4.0 etc.
I don’t really care what language which one uses, it’s none of my business. One can write most of the not-unity-specific code in F# or Visual Basic if he wants. However, I can’t agree with some arguments:
Multilingual MSDN, IDE that highlights the errors you make, and IntelliSense that works(C#) vs non-existent language reference, kind of IDE, and code completion that works most of the time (UnityScript)
and vice versa
C#
var x = 1812;
UnityStript
var x = 1812;
C#
int x;
UnityStript
var x : int;
C#
var list = new List<int> { 1, 3, 5, 7, 11, 13 };
var enemy = new Enemy
{
position = Vector3.zero,
health = 1f,
status = Status.Idle,
};
I came from an actionscript background and started with Javascript (or Unity’s implementation of it). I recently switched to C#, and will probably never be going back to javascript if I can help it.
C# is more complicated than Javascript, but you can also do much more with it.
The biggest issue I’ve found is when you mix Javascript and C# together, especially if you’re using some third party Android plugins. I had a lot of trouble trying to access javascript variables from C# that didn’t exist yet because the C# code was compiled first.
Anyway, use what you’re comfortable with. They’ll all get the job done. Most of the scripts on here and the Unify Community are in Javascript, so if you plan on using those, starting with Javascript will make your life easier.
May you tell the others how long you took to learn C# (not counting in the .NET/Mono classes or Unity3D API)?
That’s something most people don’t realize. Learning C# is pretty fast, 2-4 weeks max. Learning to fully utilize the .NET/Mono Framework and/or Unity3D API takes 6+ Months. But learning an API or SDK has nothing to do with learning the language. If I’d switch from Unity3D to Torque or XNA, I would have to learn their APIs and that’s what takes most time.
It wasn’t long at all. I’d been reading and modifying other people’s C# scripts in my own projects for a while before I dove in and made the switch.
I don’t think I even did any C# tutorials. I just jumped right in and started doing it. (not that I’m a genius or anything. It was just not all that hard)
the biggest hangups for me was how you declare variables (type name rather than name : type) , declaring functions that have return values, and how you have to create an IEnumerator function if you want to use a yield statement.
Ahahah good point Timbecile, yes basically those are the steps to convert some UnityScript to C# and I found quite easy to perform such a task on simple scripts. A litte longer on bigger code, but is a matter of patience.
The only downside of having 3 different languages, is that user A which knows great Javascript, hence using also Class{} in UnityScript and all the correct syntax and tricks, can’t make a useful system/script for user B, who is starving for a script that makes what CiccioFigata.js is making, and the more sad, is the Boo guy, that can’t use those, in its total Boo project.
Because it will be tricky (not impossible) to call functions/classes from other languages, the best choice is always write all your code in the SAME language. Whatever it is. And when you find a kick ass script, which is not in your language, put it in the plugin folder ,or just translate it in your language!
I think here we can also have 2 different “visions” of the problem:
A) - Learning / Career “vision”
B) - Producing something to feed the kids “vision”
A) If you want to learn how to code in a object oriented manner, and be ready for other kind of challenges outside the WebGL / Unity3D world, with other API(s) and in general, learn how to code properly, I’d strongly suggest you go for C# for many reasons are stated above by other users.
B) If you need to earn the money to feed your kids, don’t be paranoid, and just get your gem our there, whatever the scripting language you use. (By the way, we made our day with our first iOS title, which is coded 100% in UnityScript).
Some things that I agreed with:
I agree here.
I disagree here. Where do they state this ?
I disagree. Only variable and function declarations take some byte more…
Agree by a various backgrounds developer point of view.
I know it always seems like the reasonable and most intellectual route in a discussion to take the role of a ‘moderate’, along the lines of “everything has its ups and downs, use what you like”.
Which is not necessarily wrong.
But I think if you spend enough time with each language, C# becomes obviously superior.
Aside from the language having more advanced functionality when you want it. The entire MSDN documentation library has C# code, and the vast majority of Mono and .NET developers use C# which allows you to turn to the .NET and Mono development communities for help. This ultimately means you have far more and better documentation for C#, far more C# examples and far more users of C# to help you.
Thanks for the replies, I’ll probably be going with C# as I love the language.
Javascript was easier to learn but I’ve found that I can write a smaller script in C# and do the same as a longer script with javascript.