neikeq/GodotSharp

More comprehensive build instructions

rcurtis opened this issue · 6 comments

It would be nice to be able to build and provide feedback to this module (I've been waiting for C# for quite a while and am excited to help out!). The issue is the build instructions are a bit unclear as to what version of Godot this will work with, where projects should go, paths, etc...

Could we get a more comprehensive set of build instructions (hopefully targeting windows as its the most common game dev platform at the moment)? I'd be happy to answer any requirement questions you may have.

Thanks,
Rob

I am going to push some changes soon so the editor automatically generates the C# API and game projects. Once that is done I will update the build instructions.
This way, the only extra step other than running scons would be to generate the glue code. That part is probably a bit confusing so I will make sure to rewrite when I update the instructions. Here is a brief explanation:
glue/mono_glue.cpp is an auto generated file that contains functions that wrap the Godot API in a way that allows C# to call them. If this file is outdated compared to your version of Godot, you will need to re-generate it. In order to do that you must follow these steps:

  • If this file is outdated, it will most likely result in build errors, so you will need to pass this additional argument to scons when building Godot in order to opt out the glue: mono_glue=no.
  • After building you must execute Godot with the arguments --mono-generate-cpp <path-to-mono-module>/glue to tell it to regenerate the glue file.
  • Now you can build Godot again with the glue enabled.

You don't need to do this for each build target, doing it once is enough.

About what version of Godot is needed, any version starting today should work (unless there is a commit that breaks something). All the compatibility breaking changes for 3.0 already finished, so there should not be any issue related to that.

I agree, the build instructions are very difficult to follow. Even if you could make a video/screen recording from beginning to end of getting it to work and post a link to it in this thread and once I can get it working on my end I'll be very happy to write up more detailed build instructions if that would help.

For instance, do I need to move the mono folder in this project into the Godot project? When you run the command "godot --mono-generate-cpp /glue" is "godot" the editor? When I run this command it tries to open the mono module as a resource it which case it just crashes.

I still haven't been able to build this after several attempts on either Linux or Windows. Godot itself I find very easy to build.

Thanks for you hard work by the way. I will be super excited once I can get this working :)

So, the crash is expected behavior at this point. Also the proper command would be godot --mono-generate-cpp /path/to/mono/glue. If you don't have the path in correctly, that will cause some issues. Here's a full guide, written for Linux:

Step 1: Git Clone the Repository

It's useful if you clone it to a folder like a Repos folder where your godot clone is stored.

Step 2: Move the mono folder into the godot/modules folder

This one is pretty simple. Just copy it, really, rather than move it.

Step 3: Compile

Use the commands to compile Godot, possibly having to add mono_glue=no to the build flags. You may also get a build error in csharp_script.cpp, which you can fix by turning if (if (FileAccess::get_modified_time(proj_assembly->get_path()) <= proj_assembly->get_modified_time()) on line 388 to if (proj_assembly && FileAccess::get_modified_time(proj_assembly->get_path()) <= proj_assembly->get_modified_time()).

Step 4: Generate mono cpp files

This is the step where you seem to be having issues. This works best from the root directory, so [user@hostname godot] bin/godot.$platform.tools.64.$extention --mono-generate-cpp modules/mono/glue in bash. Godot will generate the C++ files, then close.

Step 5: Recompile

You will need to recompile Godot to build with the glue. Shouldn't take too long, just run the Godot build commands.

Step 6: Generate GodotSharp.csproj

So, when you are ready to set your Game up with C#, you run godot --mono-generate-cs /path/to/project. This will output the solution files for GodotSharp.dll and the needed C# scripts, then close.

Step 7: Build GodotSharp.dll

Using msbuild in the directory of your project, run msbuild GodotSharp.csproj. You will need to msbuild system installed. It will likely be generated in bin/debug/GodotSharp.dll.

Step 8: Create a .csproj for your game.

This is easiest with MonoDevlop on Linux, so I'll right the instructions for that right now. In MonoDevelop, create a new classlib, named the same as your project file. You may need to rename your project in your project.godot or in the Project Settings menu of Godot to match whatever project name you type - MonoDevelop on Linux does not accept spaces or dashes, and your Project Name must exactly match the name of the .csproj for Godot to see it.

Step 9: Hooking up the GodotSharp.dll

So, at this stage, you will need to manually add GodotSharp.dll as a reference in your .csproj. your ItemGroup section should look like this:

  <ItemGroup>
    <Reference Include="System" />
    <Reference Include= "GodotSharp">
      <HintPath>path/to/GodotSharp.dll</HintPath>
    </Reference>
  </ItemGroup>

Step 10: Adding .cs files

Whenever you want to add a C# script to your project, you can use the regular New Script menu, choosing the C# option. Then to get it to be included in the game, you will need to <Include> it in an ItemGroup section of your project.cs file. For example:

  <ItemGroup>
    <Compile Include="path/to/script.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>

Step 11: Runing the game

Once you have everything set up, run msbuild project.csproj, and then your scripts should work when you hit the play button, as long as they're properly attached to an object.

Now you should be good to go.

Thank you so much! Those instructions are much more clear. I have it working now. Very exciting! :)

I made a pull request because it looks like Godot's methods like "get_instance_ID" have been changed to have a lowercase "id".

IE. "get_instance_ID" is now "get_instance_id"

No prob, glad you figured it out 👍

I've updated the build instructions to make them more comprehensive. I also removed the steps that are no longer necessary.