Hacker News new | past | comments | ask | show | jobs | submit login
Introducing C# in Godot (godotengine.org)
86 points by strangecasts on Oct 21, 2017 | hide | past | favorite | 28 comments



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;
    }


Or:

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


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


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


It might be if they used the One True Brace style ;)


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.


I believe Unity was investigating embedding the .NET Core runtime instead, for performance gains due to a better GC and better JIT.

Therefore I find it very odd they chose to use the Mono runtime. It sounds to me the .NET Core runtime is a much better choice, since the underlying CLR is in the basis the same as the .NET Framework CLR, including the Ryujit and all the other goodies.


Unity targets many systems where .NET Core doesn't exist, e.g. games console.

Mono is only used in some targets, they actually compile to native code via IL2CPP for production deployment.


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.


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


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 (Sep 2017, 131 comments)


I think your links goes to this post.


Doh! Thanks for letting me know.

https://news.ycombinator.com/item?id=15309989


Nuget support would be amazing..


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..


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-...

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#.


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

Yes, the standard build doesn't make use of the C# module.


>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).


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.


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


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


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.


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.


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.


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.


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.


I have bad news for you; Mono 5.0 launched with Roslyn which I believe is what brings C#7 support. Roslyn is of course a MS project. Ditto for MSBUILD.


So will installing a version of Godot that supports C# get me something reporting back to MS out of the box?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: