
Introducing C# in Godot - strangecasts
https://godotengine.org/article/introducing-csharp-godot
======
Arnavion
Note to the author: Since you specifically point out that C# 7.0 is supported,
this example:

    
    
        if (ev is InputEventMouse)
        {
            var mouseEvent = (InputEventMouse)ev;
            Vector2 mousePos = mouseEvent.Position;
        }
        else if (ev is InputEventKey)
        {
            var keyEvent = (InputEventKey)ev;
            bool aPressed = keyEvent.Pressed && keyEvent.Scancode == GD.KEY_A;
        }
    

would be better written as:

    
    
        switch (ev)
        {
            case InputEventMouse mouseEvent:
                Vector2 mousePos = mouseEvent.Position;
                break;
    
            case InputEventKey keyEvent:
                bool aPressed = keyEvent.Pressed && keyEvent.Scancode == GD.KEY_A;
                break;
        }

~~~
knocte
I think switch blocks are only worth it when you have 2 or more `else if`,
otherwise a normal `if` is more readable IMHO.

~~~
n4r9
Normally I'd agree, but I really like the concise but readable way this
handles the casting for you.

------
apk-d
This is fantastic! This actually puts the engine ahead of Unity in terms of
scripting since those guys target a rather outdated version of C#/Mono. Now I
can't wait to play around with Godot.

(Modern) C# is my favorite language, but I've been looking into F# recently.
Wonder if someday that might be an option in Godot as well. Given how both
languages compile to the same binary format, there have been workarounds to
use it in Unity even though it's not officially supported.

~~~
pjmlp
Unity compiles C# to actual native code via IL2CPP, Godot doesn't do it, as
far as I can understand it.

The Unity is already supporting 4.6 on its beta version.

~~~
SugoiDev
4.6 is supported on all versions after 2017.1, but it is still labeled as
experimental and not enabled by default.

------
j_s
There was a lot of excitement about C# support coming in v3.0 back in last
month's discussion:

Godot Engine – Free and open-source 2D and 3D game engine |
[https://news.ycombinator.com/item?id=15523416](https://news.ycombinator.com/item?id=15523416)
(Sep 2017, 131 comments)

~~~
Yuioup
I think your links goes to this post.

~~~
j_s
Doh! Thanks for letting me know.

[https://news.ycombinator.com/item?id=15309989](https://news.ycombinator.com/item?id=15309989)

------
Rapzid
Nuget support would be amazing..

------
crudfactory
Can I build/use future Godot releases without any mono/microsoft dependencies?

I notice the post reveals ms has funded the project now. I hope Godot doesn't
owe ms any favours..

~~~
giancarlostoro
You don't have to use the C# features of Godot. You can still use GDScript to
code your game in, or GDNative with any extending language like D, Go, or
Rust, so long as you find bindings for them. I wouldn't worry about Microsoft
being owed favors, I'd worry more about actual licensing, and if it wasn't for
Microsoft (or so I suspect) Mono would still not be as openly licensed as it
is now[0].

[0]: [http://www.mono-project.com/news/2016/03/31/mono-
relicensed-...](http://www.mono-project.com/news/2016/03/31/mono-relicensed-
mit/)

Note how Microsoft was mentioned for their license change (why would that be
if Microsoft had nothing to do with the change, wondering if buying out
Xamarin gave them power over making Mono more open), and it was announced at
the annual big Microsoft event no less. I'm all for yelling at Microsoft when
they screw up, but they're doing good things with .NET and C#.

------
mappu
_> As of alpha2, Godot is using Mono 5.2 and C# 7.0 is supported._

This is an explicit dig at Unity, which is still(?) on Mono 2.x and C# 3.5
owing to their custom IL2CPP toolchain (with Mono 4.x / C# 6 in beta for the
editor only).

~~~
WillPostForFood
It is a valid bragging point for Godot that probably doesn't have much to do
with Unity which had been trapped in an old version of mono for licensing
reasons (not because of the toolchain - it was the other way around). Unity
has been able to start updating now that Microsoft opened up and bought
Xamarin), and is now offering Mono/.Net 4.6 and C#6 and I assume will continue
to modernize.

~~~
pjmlp
It wasn't licensing reasons but monetary ones, rather Unity did not want to
pay Xamarin what they asked for.

~~~
WillPostForFood
Same difference - they had a license for an old version and didn't want to pay
to upgrade.

------
jasonkostempski
Is Mono not dying due to .NET core? It seems to be popping up in a few new
places but I would have thought new projects would be avoiding it.

The last thing I want is any dependency on MS tooling as they've shown
everything they release will include telemetry. I'm just getting started with
game dev and I really like Godot, but if the future is going to require MS
anything, I'm going to jump ship.

~~~
kevingadd
Mono is still supported. .NET core and Mono solve different problems - for
example (this surprised me), unlike Mono and the windows .NET Framework, .NET
core can't just run random .NET executables you download off the internet. You
have to build a core-targeted project from source. Mono also handles cross-
platform scenarios like mobile & mac frontend apps right now that .NET core
won't be a good fit for in the near future.

~~~
cptskippy
Mono, .NET Framework, .NET Core, Xamarin.<Platform>, etc are all just
different implementations of .NET Standard. I believe .NET Framework is a
superset of Core.

They can all run code targeted at Standard but all have slightly different
libraries on top of Standard. Mono was originally was intended to be a cross
platform stand-in for .NET Framework which is why they can mostly run the same
code. I believe Mono and Framework are slowly merging together.

~~~
AdeptusAquinas
I don't think this is true. Framework for example can only reference standard
libraries as of 4.6.2. Up until dotnet core 2.0, core was very much an
incompatibile subset of framework - even with 2.0 it would be better
characterised as a cross platform rewrite of the net framework.

~~~
pjmlp
Actually .NET Standard 2.0 requires .NET 4.6.1.

.NET 4.6.2 was only for .NET Standard 1.0, but they realised basing on 4.6.1
would be a more sensible decision and fixed it in version 2.0.

