Defold + C# support
Note: This feature is still experimental and under development
NOTE: This is available from the 1.9.7 BETA
Why are we doing this?
In the past, we’ve seen studios considering Defold, but coming from an eco system with C# support, with battle tested C# code, they had no easy way to migrate their code. This way, we can offer those studios a chance to more thoroughly consider the Defold game engine.
More information can be found in this FAQ topic.
What does C# support give me?
Similar to C++ support, it lets you write extensions or game logic using C#.
It is not scripting
To make things clear, neither of the “low level” api’s (C, C++ C#) are giving you scripting support.
Changes to your extension code will always require a build on the build server.
As such, this is not scripting, and the turnaround times will increase for you.
When writing game logic, you likely will do a lot more heaving lifting on your part compared to what our Lua implementation already gives you.
How do I get started?
We have an example project where we test our language support:
https://github.com/defold/example-languages
You should be able open the project in Defold 1.9.7 BETA and newer and press Project → Build.
As with other supported languages, either put your .cs
files in the extension/src
folder, or put a statically linked library (.a/.lib) in the extension/lib/<platform>
folder.
What platforms are supported?
Currently, these platforms are supported:
- macOS - arm64
- iOS - arm64
- Android - arm64
- Windows - x64
Linux support is coming.
For the rest of the platforms, we refer to the list Microsoft published here: C# NativeAOT platform support
Documentation
Currently we don’t have a good way to display multi language documentation, so we refer you to the source code. (*.cs files that reside in the dmsdk folder):
- dmsdk/extension/extension_gen.cs
- dmsdk/extension/extension.cs
- dmsdk/lua/lua.cs
- dmsdk/lua/lua_gen.cs
- dmsdk/lua/lauxlib_gen.cs
- dmsdk/lua/lual.cs
- dmsdk/dlib/hash_gen.cs
- dmsdk/dlib/configfile_gen.cs
Performance
Build size
Here we measure the excutable size when having no extension, or a certain extension, or all of them.
In the case of Android, it’s the bundle size that reported.
Version | macOS | iOS | Android | Win64 |
---|---|---|---|---|
Default | 4579952 | 3010416 | 2377011 | 7238656 |
Cpp | 4579968 | 3010496 | 2381107 | 7242752 |
CSharp | 6473872 | 4525728 | 3032371 | 8652800 |
All | 6473888 | 4525792 | 3032371 | 8656384 |
Runtime tests
Here we test some simple tasks:
- 1000000 iterations
- time in seconds
- Rot13() - calling rot13() on a short string
- Add() - adding two numbers
Rot13() | macOS | iOS | Android | Win64 |
---|---|---|---|---|
Lua | 0.837545 | 5.070099 | 4.849964 | 1.157000 |
Cpp | 0.083666 | 0.563236 | 0.52723 | 0.117027 |
CSharp | 0.248221 | 0.836858 | 3.393554 | 0.303551 |
Add | macOS | iOS | Android | Win64 |
---|---|---|---|---|
Lua | 0.586649 | 0.456694 | 0.290245 | 0.071997 |
Cpp | 0.413572 | 0.483642 | 0.414745 | 0.076998 |
CSharp | 0.425094 | 0.504217 | 0.609277 | 0.114061 |
Testing
We hope for the interested users to test the functionality and help find problems with the support.
Thanks!