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 spine-godot runtime documentation. Follow the documentation there for basic installation instructions.


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 Microsoft's official download site and restart Godot.


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 SpineSprite node:

C#:

using Godot;
using System;

public partial class SpineSprite : SpineSprite {
   public override void _Ready () {
      GetAnimationState().SetAnimation("run", true, 0);
   }
}

Compared to the same code written in GDScript, there is little difference except that the API uses PascalCase and requires a semicolon at the end according to C# code conventions.

GDScript:

extends SpineSprite

func _ready():
   get_animation_state().set_animation("run", true, 0)

In GDScript, you can get the skeleton outside of a function using the @onready annotation. In C#, you cannot call the API in class definitions so you have to get it inside a function. Here is a comparison of C# and GDScript code to flip the skeleton and queue animations:

C#:

using Godot;
using System;

public partial class SpineSprite : SpineSprite {
   private SpineSkeleton spineSkeleton;
   private SpineAnimationState spineSpriteAnimState;

   public override void _Ready () {
      spineSkeleton = GetSkeleton();
      spineSpriteAnimState = GetAnimationState();
      spineSkeleton.SetScaleX(-1);
      spineSpriteAnimState.SetAnimation("idle", true, 0);
      spineSpriteAnimState.AddAnimation("run", 2, true, 0);
   }
}

GDScript:

extends SpineSprite

@onready var spineSkeleton : SpineSkeleton = get_skeleton()
@onready var spineSpriteAnimState : SpineAnimationState = get_animation_state()

func _ready():
   spineSkeleton.set_scale_x(-1)
   spineSpriteAnimState.set_animation("idle", true, 0)
   spineSpriteAnimState.add_animation("run", 2, true, 0)

For the details of how the APIs are mapped from GDScript to C#, please refer to the Godot C# documentation.


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!

spine-godot C# support

September 5th, 2023

We're happy to announce that our spine-godot runtime now supports programming using the C# language! You are no longer limited to GDScript. C# support lets you use a feature rich IDE and can greatly increase productivity for complex games.

Please note that currently C# support in Godot 4.x is available only for desktop operating systems. As the Godot team expands platform support, our Godot binaries and export templates will be updated accordingly.

Start using C#

To get started, please visit our spine-godot documentation page and download the latest Godot + Spine binary with C# support for your operating system. Currently we provide binaries for the latest Godot stable release, which is 4.1.1.

Once you have successfully installed the Godot binary, follow the C# project setup guide to either initiate a new project or convert an existing one to utilize C# and Spine-Godot.

For more information on this topic, check out our new blog post about setting up a C# project.

Congratulations! You are now ready to develop your Godot games with Spine and C#!

Discuss this blog post on the Spine forum!

Getting Started with spine-ue4

July 27th, 2023

Learn how to use Spine in Unreal Engine! In this video we show you how to install spine-ue4, import your Spine skeletons, and check out the example projects.

Keep an eye out for our next video where we will dive deeper into the examples to learn more about each component.

Did you find this video useful? Join the discussion of this post on the Spine forum!

spine-phaser Runtime released

June 30th, 2023

/img/blog/spine-flutter/spine-flutter.png

We're happy to announce the general availability of our brand new spine-phaser runtime.

Phaser has been one of the most beloved Web game engines for many years now. While Richard Davey and his team of OSS contributors created their own Phaser Spine Plugin, the Phaser team has many other duties. After discussion with Richard, we agreed that creating and maintaining an official Spine runtime for Phaser would be the most beneficial for both the Spine and Phaser communities -- that is what we are releasing today!

Here's a minimal example. Click the JS tab to see the code:

See the Pen Untitled by Mario Zechner (@badlogicgames) on CodePen.

If you are a seasoned Phaser developer who's used the Phaser Spine Plugin, you'll find a few differences with our official spine-phaser runtime. spine-phaser supports both JSON and binary skeleton data files. It also separates loading of skeleton and atlas data, allowing you to reuse the same atlas for multiple skeletons, improving performance.

Another benefit to using the official spine-phaser runtime is that we guarantee timely updates and bug fixes in lock step with our Spine Editor releases. And for Davey and team, we can take away some of their burden, which will free them up to spend more time on Phaser itself.

To learn more, check out our spine-phaser documentation and have a look at the example code. We've ported many of the original Phaser Spine Plugin samples to our official runtime, which should make switching to the official runtime an easy endeavor.

Discuss this blog post on the forums!