How to Add C# Assemblies to a Godot Engine Project

With the release of version 3.0 of the Godot Engine, C# was added as a supported programming language. Due to other engines like Unity, there is a large number of C# assemblies which can help in developing a game. However, there isn’t an easy way to add assemblies in the editor. Therefore, this tutorial was created to help with that problem.

In this tutorial, we’ll use the Godot Engine, version 3.0, along with the assembly for Rant. Note that while a C# assembly can be added to the editor, the assembly cannot be exported to a self-contained executable just yet.

Update: as of version 3.0.5 of the Godot Engine, exporting C# projects with assemblies have become possible.

1. Create project as normal. Where necessary, add a C# script. At first, the engine will generate the necessary C# files (i.e. the “*.csproj” and “*.sln” files).

2. Add in the C# code. After this, close the editor for the moment.

3. Ensure that the correct assembly is in the Godot project working directory.

4. Go into a desirable IDE and open up the “*.csproj” file which was created when the C# script was added. Monodevelop will be used in this tutorial. At this point, ensure that the Godot editor isn’t running. Otherwise, key files may be overwritten.

5. In Monodevelop, right-click on the References node in the tree view for the project and click on Edit References... Be sure to first expand the project so as to reveal References. Then click on the .NET assembly tab and click “Browse…”.

6. Select the desired assembly for the project and then click “Open”.

7. It should then be added as a reference for the project. Click “OK” and save the project (“Ctrl + S” or “File -> Save”). Exit out of the IDE and go back into the Godot editor.

8. Add in a GDscript which makes use of the assembly.

9. If all goes well, the engine should use the assembly in the resulting game.

If you have any comments or questions, please ask them below, or get in touch with me.

Using Rant in my Python program because I’m a glutton for punishment

Over the past few months, I have been researching and developing a little procedurally generated game which will eventually be created in the Godot engine. This game will have a story that’s procedurally generated for the players. A part of this game is the dialogue, which will also be procedurally generated. To accomplish this, I set out to find a library of some kind which can create procedurally generated dialogue (or at least the dialogue that I want) and is written in my programming language of choice, Python. From the looks of it, there isn’t one, and so I had to look elsewhere. That’s when I stumbled upon something called Rant. This is billed as a library which can procedurally generate dialogue. At first I thought I had found what I was searching for. Sadly, though, it is written in  the least open source-friendly language I have ever seen: C#. This can be used on Linux (with the Mono runtime). But I’m looking for a solution where I don’t have to use a bunch of programming languages to achieve what I want.

At first, I tried making some kind of dialogue scheme that would suit my needs. I threw in some sentences of what may define the NPC, and mashed it all together. From the looks of it, though, the scheme is getting out of hand. I have several lines of dialogue, and I’m not even finished. I don’t entirely know how I’ll fit it all together, considering this is just for a simple demo of the full game. It looks like I’m going to have to get creative.

I went digging and searching around I came upon several possible ways of integrating C# code into Python code. There’s IronPython, a fully implemented version of Python in C#. The big problem with this was that it didn’t look very portable to me, as I would have to bundle the .NET libraries with the game for each platform, and that’s a royal pain the ass. Then I looked at Python.NET, which looked very promising: you can call some C# code from Python, and you can call some Python code from C#. It looked like the best of both worlds. Now, actually making it work is a bigger problem.

When I tried to use the Rant.dll assembly in my Python program, I found that I can’t do that because, well, it’s C# code, and the regular old CPython (which comes with many Linux distributions) can only import C or C++ code. Then I looked into using the clr module from Python.NET, but I couldn’t find a version built for Linux. Through a lot of hand wringing, brow beating, and code cracking, I found that I had to use the latest version of Mono (version 5.0.1) along with an unstable version of Python.NET. This one built with the suggested command: python setup.py build_ext --inplace. The built shared object library file, “clr.so”, and the “clr” module load in Python.  Heck, I was even able to load the pre-built “Rant.dll”. But this is nothing compared what I must do now: actually making some procedurally generated dialogue with Rant. And I don’t know where to begin with that.

Interesting video on designing programming languages

Yesterday, I started watching this video on programming languages, and it took me over forty minutes to stop watching the video. It’s not because that the video was over an hour long, but rather the subject matter of the video.  It’s a presentation by Brian Kernighan titled “How to succeed in language design without really trying”.  The presentation by professor Kernighan was very well done.  He went through a bit of history with how some programming languages came about, as well as their usees.  He also talked about his time with Bell Labs, and how he, along with two other great programmers, wrote the language awk.  The video had me interested because, for one, I could understand half of what professor Kernighan said, and two, he admitted that he threw the language together out of necessity.  Also, he would, at times, remind the audience of his short comings, such as with functional programming languages, and remembering how to program in C.