Setting up spine-godot with C#

October 2nd, 2023

This blog post briefly explains the steps to get started using C# with spine-godot and how it differs from using GDScript.

  • Installation

    You can download our pre-built Godot 4.1 editor and export template binaries with C# support from the C# project setup

    To use our Godot editor binaries with C# support, you need to take an extra step when setting up a new Godot project:

    1. Create a Godot project

    First, create a new Godot project using the downloaded Godot editor binary that has C# support.

    Failed to load .NET runtime

    If the Godot editor fails to load the .NET runtime, the following error message will appear at startup:

    As described in the message, please install the .NET SDK 6.0 or later from 2. Create a godot-nuget folder

    Close Godot and open your project folder. In the root directory, create a new folder called godot-nuget.


    3. Copy the C# assemblies

    Copy the Godot C# assemblies into the godot-nuget folder. If you are using Windows or Linux, you can find the assemblies in the downloaded Godot editor ZIP file:

    • Windows: godot-editor-windows-mono.zip\GodotSharp\Tools\
    • Linux: godot-editor-linux-mono.zip/GodotSharp/Tools/

    If you are using macOS:

    • macOS: Navigate to Godot.app/Contents/Resources/GodotSharp/Tools/ by right clicking the Godot.app file in Finder, select Show Package Contents, then navigate to Contents/Resources/GodotSharp/Tools/.

    Copy the following files into your godot-nuget folder:

    • GodotSharpEditor.<version>.snupkg
    • Godot.NET.Sdk.<version>.nupkg
    • Godot.SourceGenerators.<version>.nupkg
    • GodotSharp.<version>.nupkg
    • GodotSharp.<version>.snupkg
    • GodotSharpEditor.<version>.nupkg

    The <version> depends on which Godot version you downloaded, e.g. 4.1.1.


    4. Create a nuget.config file

    Finally, create a new file called nuget.config in the root directory of your project with the following content:

    <configuration>
    <packageSources>
        <!-- package source is additive -->
        <add key="godot-nuget" value="./godot-nuget" />
    </packageSources>
    </configuration>

    This configures the godot-nuget directory to be a package source for NuGet packages. Instead of fetching the official Godot C# assemblies from the NuGet package registry, the assemblies from the godot-nuget directory will be used, which also include the C# bindings for the spine-godot runtime.


    You can now open your project in Godot and use the Godot and spine-godot C# APIs instead of GDScript!


    Animate a skeleton with C#

    Here is simple example code to animate a Spine skeleton with a C# script attached to a C# examples

    To inspect and experiment with the C# examples for spine-godot:

    1. Clone the spine-runtimes Git repository or download the latest version as a ZIP and unzip it.
    2. Open the spine-runtimes/spine-godot/example-v4-csharp/ folder and click the project.godot file to open it.

    You can find various example scenes and scripts using C# under the examples folder in the FileSystem dock.


    If you are having trouble using spine-godot with C# support, don't hesitate to post your questions on the Spine Forum!