Skip to main content

Spine

Luna supports Spine up to version 4.2 beta.

Spine is an animation tool that focuses specifically on 2D animation for games. For more information, check out the website.

Install Spine

Since Playable 3.8.0, Spine can easily be added to your project:

  1. Download Spine from on their website.
  2. Move the Spine Unity package into your project directory in Unity.

Native JS Spine Compilation

With the latest version of Playable Plugin, we now offer support for Native JS Spine for versions 4.0 and 4.1.

This feature grabs the original JavaScript Spine sources instead of transpiling them from C# code with Bridge. As a result, the performance of your creative is improved.

This feature is active by default at runtime.

Switching Back To Bridge Compilation

If you wish to switch back to the Bridge compilation, follow these steps:

  1. Locate the luna.json file in your project directory.
  2. Find the forceSourcesBasedCompilation field.
  3. Set this field to true to force C# compilation.
Please note that switching back to C# compilation is more stable, but less performant.

Configure Spine with older versions of Playable

Prior to Playable Plugin 3.8.0, you were able to use spine animations in your projects, but some of the scripts necessary to generate the animations were not compatible with Luna. As a result, you had to make changes to the plugin scripts to accommodate this.

Below you will find a guide specifically for developers who use Spine in their Unity projects with Playable versions older than 3.8.0.

To save time and avoid complications, we recommend using the latest version of Playable Plugin.

Click here for instruction on how to configure Spine with older versions of Playable Plugin
Please use this guide only if you are using a Playable version prior to 3.8.0.

This guide is for developers who are using Spine in their Unity projects as DLLs.

  1. Download Spine from on their website.
  2. Move the Spine Unity package into your project directory in Unity.

If you try building with the Luna Plugin now, you will receive errors in the diagnostics box. Don't worry these can be fixed by following the rest of these steps:

  1. First remove the Spine Examples folder from your project or exclude from the Luna build.

images-xsmall

  1. Next you will need to alter files in the Spine/Runtime/spine-csharp folder, specifically the ones highlighted in the image below:

images-medium

These changes are required to ensure the code is compatible and can be compiled with Luna.

Animation.cs

Inside the public class ScaleTimeline, cast to float all calculations starting with either bone.scaleX or bone.scaleY.

// Before
bone.scaleX = bx + (Math.Abs(x) * Math.Sign(bx) - bx) * alpha;

// After
bone.scaleX = (float)(bx + (Math.Abs(x) * Math.Sign(bx) - bx) * alpha);

Also cast to float all lines starting bx = Math.Abs(... or starting by = Math.Abs(....

// Before
bx = Math.Abs(bone.data.scaleX) * Math.Sign(x);

// After
bx = (float)(Math.Abs(bone.data.scaleX) * Math.Sign(x));

Atlas.cs

Use the finder to locate all references to CultureInfo.InvariantCulture, and remove all them from the script.

Bone.cs

Find the line containing s = Math.Abs(pa * pd - pb * pc) / s; (will be within the case TransformMode.NoRotationOrReflection: block, around Line 191), and cast it to a float.

//Before
s = Math.Abs(pa * pd - pb * pc) / s;

// After
s = (float) (Math.Abs(pa * pd - pb * pc) / s);

Json.cs

Find the line containing builder.Append(stringBuffer, 0, idx); (will be within if (idx >= stringBuffer.Length) block, around Line 203). Initialise the stringBuffer variable as a new string.

// Before
builder.Append(stringBuffer, 0, idx);

// After
builder.Append(new string(stringBuffer), 0, idx);

Last thing to do in this script is to find all references to NumberStyles.Float, NumberStyles.Any and CultureInfo.InvariantCulture and wrap them in a #if !UNITY_LUNA.

Add another #if UNITY_LUNA directly under the first one, and copy and paste the if statement within it but remove references to NumberStyles.Float & CultureInfo.InvariantCulture this time.

For example, your ParseFloatNumber() function should look like this after this process:

public float ParseFloatNumber()
{
float number;
var str = GetNumberString ();

#if !UNITY_LUNA
if (!float.TryParse (str, NumberStyles.Float,CultureInfo.InvariantCulture, out number))
return 0;
#endif

#if UNITY_LUNA
if (!float.TryParse (str, out number))
return 0;
#endif

return number;
}

IkConstraint.cs

Find the line containing float s = Math.Abs(pa * pd - pb * pc) / (pa * pa + pc * pc); (will be within the Apply function, around Line 173). Change the type of s from float to double.

3 lines below this there will be 2 calculations to set the values for variables pb and pd, these also need to be cast to a float.

For example:

// Before
pb = -sc * s * bone.skeleton.ScaleX;

// After
pb = (float) (-sc * s * bone.skeleton.ScaleX);

SkeletonBinary.cs & SkeletonJson.cs

Find and remove all references to FileAccess.Read and FileShare.Read. They will be located in FileStream constructors, but you won't need to replace them with anything.

You can delete these references, or wrap them in a scripting define symbol as explained here.

#if UNITY_LUNA
using (var input = new FileStream(path, FileMode.Open));
#else
using (var input = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read));
#endif

  1. Next you need to alter files in the Spine/Runtime/spine-unity/Utility folder, specifically the 2 highlighted in the image below:

images-medium

AtlasUtilities.cs, AttachmentRegionExtensions.cs & AttachmentCloneExtensions.cs

Exclude these scripts from being included in the Luna build. To do so go to the Luna Plugin, click on the Code section and then from within there go to the Exclusions tab. From here you can expand your hierarchy to locate the scripts to tick and therefore exclude.

images-medium

SkinUtilities.cs

Wrap the following lines with the Luna defines symbol.

#if !UNITY_LUNA
Attachment clonedAttachment = e.Value.GetCopy(cloneMeshesAsLinked);
destinationAttachments[new Skin.SkinEntry(e.Key.SlotIndex, e.Key.Name, clonedAttachment)] = clonedAttachment;
#endif
...

#if !UNITY_LUNA
Attachment clonedAttachment = e.Value.GetCopy(cloneMeshesAsLinked);
destinationAttachments.Add(new Skin.SkinEntry(e.Key.SlotIndex, e.Key.Name, clonedAttachment), clonedAttachment);
#endif

SkeletonExtensions.cs

Find the line containing s = Math.Abs(pa * pd - pb * pc) / s; (will be within the case TransformMode.NoRotationOrReflection: block, around Line 353), and cast it to a float.

// Before
s = Math.Abs(pa * pd - pb * pc) / s;

// After
s = (float)(Math.Abs(pa * pd - pb * pc) / s);

  1. Next you need to alter files in the Spine/Runtime/spine-unity/Components folder, specifically the 2 highlighted in the image below:

SkeletonMecanim.cs

Find the line containing layerNames[i] = animator.GetLayerName(i); (will be within public string[] MecanimLayerNames, around Line 200) and wrap it with the Luna defines symbol.

#if !UNITY_LUNA
layerNames[i] = animator.GetLayerName(i);
#endif

SkeletonRenderer.cs

Preprocess (wrap within a #if !UNITY_LUNA) the following lines:

public SpriteMaskInteraction maskInteraction = SpriteMaskInteraction.None; (Should be around Line 140).

AssignSpriteMaskMaterials(); (Should be around Line 490).

The entirety of the private void AssignSpriteMaskMaterials() function (Should begin just after Line 572)


SkeletonRenderSeparator.cs

Second to last is to alter one script in the Spine/Runtime/spine-unity/Components/SkeletonRenderSeparator folder, specifically SkeletonRenderSeparator.cs

Wrap the following lines with the Luna defines symbol.

#if !UNITY_LUNA
var motionVectorGenerationMode = mainMeshRenderer.motionVectorGenerationMode;
#endif
...

#if !UNITY_LUNA
var probeAnchor = mainMeshRenderer.probeAnchor;
#endif
...

#if !UNITY_LUNA
mr.motionVectorGenerationMode = motionVectorGenerationMode;
#endif
...

#if !UNITY_LUNA
mr.probeAnchor = probeAnchor;
#endif
  1. Lastly, exclude the following script from being included in the Luna build.

SpineSpriteAtlasAsset.cs

To do so go to the Luna Plugin, click on the Code tab and then from within there go to the Exclusions tab. From here you can expand your hierarchy to locate the script(s) to tick and therefore exclude.

Having problems with Spine? Check our Plugins Common Issues.