GDScript vs. C# in Godot: Which language should you use?
Godot is a powerful and versatile game engine that supports two scripting languages: GDScript and C#. Both languages have their own advantages and disadvantages, so it’s important to choose the one that’s right for you.
Official support
Both GDScript and C# are officially supported by the Godot team. This means that both languages have equal access to the Godot API and documentation.
Popularity
GDScript is by far the more popular language in Godot. It’s supported by a large community of developers. C#, on the other hand, is a newer addition to Godot, but it’s quickly gaining popularity, especially among developers who are already familiar with the language.
Tutorials and resources
There are more tutorials and resources available for GDScript than for C#. This is because GDScript has been around for longer, and it’s the default language for Godot. However, the C# community is growing rapidly, and more tutorials and resources are becoming available all the time.
Your existing skills matter
Your existing skill set and personal preferences are the most important factors to consider when choosing between GDScript and C#.
If you’re already familiar with C#, or if you have experience with other statically typed languages, then C# will be a more natural choice for you. You’ll be able to get started quickly, and you’ll be able to leverage your existing knowledge and skills.
On the other hand, if you’re new to programming, or if you have experience with dynamically typed languages like Python, then GDScript may be a better choice for you. GDScript is easier to learn, and it has a more forgiving syntax.
Ease of prototyping
GDScript is generally considered to be easier to prototype with than C#. This is because GDScript has a more relaxed syntax, and it doesn’t require as much boilerplate code. C#, on the other hand, is a more statically typed language, which can make it more difficult to prototype quickly.
Applicability beyond Godot
C# is a more widely applicable language than GDScript. C# is the primary language used in the Unity game engine, and it’s also used in a variety of other game development tools and libraries. GDScript, on the other hand, is specific to the Godot game engine.
Syntax and style
GDScript is a Python-like language, with a simple and easy-to-read syntax. C#, on the other hand, is a more verbose language with a more traditional C-style syntax.
Type safety
GDScript has a level of optional type safety. This means that you can choose to use type hints to make your code more type-safe, but it’s not required. C#, on the other hand, is a statically typed language, which means that all variables and expressions must have explicitly defined types.
Static vs. dynamic typing
Static typing can help to prevent errors and make your code more maintainable. However, it can also make your code more verbose and difficult to prototype with. Dynamic typing, on the other hand, can make your code more concise and easier to prototype with, but it can also lead to more errors.
IDEs
C# has several professional IDEs available, such as Rider, Visual Studio and Visual Studio Code. GDScript, on the other hand, doesn’t have any dedicated IDEs. However, GDScript can be used with any text editor, and there are several plugins available that provide IDE-like features, such as syntax highlighting, code completion, and debugging.
Ecosystem
The .NET ecosystem is massive in comparison to the GDScript ecosystem. This means that there are a lot more libraries and tools available for C# developers.
Debugging
It’s generally easier to get hard to fix runtime bugs in GDScript than in C#. This is because GDScript is dynamically typed, so you can inspect and modify variables at runtime. C#, on the other hand, is statically typed, so it can be more difficult to debug runtime errors.
Using both GDScript and Csharp
It is possible to use both C# and GDScript in the same Godot project (but definitely not required). This can be useful for a variety of reasons, such as:
You could leverage the strengths of both languages. For example, you could use C# (or even C++) for performance-critical code, and GDScript for prototyping and scripting simple game mechanics.
However, there are also some potential drawbacks to using both C# and GDScript in the same project:
It can be more difficult to maintain a project that uses multiple languages. This is because you need to be aware of the differences between the two languages, and you need to make sure that your code is compatible with both languages.
It can be more difficult to debug a project that uses multiple languages. This is because you need to be able to debug code written in both languages.
Language interoperability
C# code within a Godot project can be difficult to remove once it is introduced. This is because GDscript calling into C# is good, idiomatic GDscript. However, C# calling into GDscript is bad C#, as it requires referencing functions by string. This can make your code more difficult to maintain and debug.
In other words, once you start using C# code in your Godot project, it can be difficult to go back. This is because GDscript is designed to make it easy to call C# code, but C# is not designed to make it easy to call GDscript code.
If you are considering using multiple languages in your Godot project, I recommend that you think carefully about whether or not you need to use C#. If you do need to use C#, try to limit the amount of code that you call.
Performance
A lot of new developers coming to Godot often worry about performance, so let’s talk about that for a bit.
GDScript vs. Csharp speed
C# is generally faster than GDScript, but this is not true in all circumstances and all situations.
Marshalling can add overhead to C# code, especially when calling native Godot functions.
Marshalling is the process of converting data between different programming languages. Godot is written in C++. When you call a native Godot function from C#, the .NET runtime needs to marshal the data between the two languages. This can add overhead to your code, especially if you’re calling native functions frequently.
GDScript, on the other hand, doesn’t need to marshal data when calling native Godot functions. This is because GDScript is built on top of the Godot engine, and it has direct access to the Godot API.
As a result, GDScript code can sometimes be faster than C# code, especially when calling native Godot functions frequently.
Does it really matter
If you’re developing a performance-critical game, then C# may be a better choice.
But for most games, the difference in performance between GDScript and C# will be negligible.
You can always write performance critical parts of your game in C++ if you find it necessary. It’s always an option whether you choose GDScript or C#.
About marshalling specifically, you can avoid any major problems simply by being mindful of the fact that marshalling happens and avoiding excessive and unnecessary back and forth between C# and Godot.
Marshalling overhead is typically only significant in performance-critical applications, and you’re likely to hit other more critical bottle necks way before that happens.
Know the scale of your game, know your skillset, know your personal preferences. There are a lot of things to consider when choosing a language and performance is only one of those.
Final words
If you’re new to game development, or if you’re looking for a language that is easy to prototype with, or you’re already familiar with Python then GDScript is a good choice.
If you’re already familiar with C#, or if you need a language with better performance or a wider ecosystem, then C# is a good choice.
Ultimately it comes down to personal preference.