Skip to main content

Spine

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

Whilst you can use spine animations in your project, some of the editor scripts which are used to generate the animations are not compatible with Luna. Therefore you need to amend the plugin scripts to accommodate for this.

This guide is for developers who are using Spine 3.8 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.


  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.

// Beforebone.scaleX = bx + (Math.Abs(x) * Math.Sign(bx) - bx) * alpha;
// Afterbone.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(....

// Beforebx = Math.Abs(bone.data.scaleX) * Math.Sign(x);
// Afterbx = (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.

//Befores = Math.Abs(pa * pd - pb * pc) / s;
// Afters = (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.

// Beforebuilder.Append(stringBuffer, 0, idx);
// Afterbuilder.Append(new string(stringBuffer), 0, idx);

Last thing to do in this script is find all references to NumberStyles.Float, NumberStyles.Any and CultureInfo.InvariantCulture and remove them. They will be within TryParse methods, but you don't need to replace them with anything.

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:

// Beforepb = -sc * s * bone.skeleton.ScaleX;
// Afterpb = (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_LUNAusing (var input = new FileStream(path, FileMode.Open));#elseusing (var input = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read));#endif

  1. Next you need to alter files in the Spine/Runtime/spine-csharp/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_LUNAAttachment clonedAttachment = e.Value.GetCopy(cloneMeshesAsLinked);destinationAttachments[new Skin.SkinEntry(e.Key.SlotIndex, e.Key.Name, clonedAttachment)] = clonedAttachment;#endif...
#if !UNITY_LUNAAttachment 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.

// Befores = Math.Abs(pa * pd - pb * pc) / s;
// Afters = (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_LUNAlayerNames[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_LUNAvar motionVectorGenerationMode = mainMeshRenderer.motionVectorGenerationMode;#endif...
#if !UNITY_LUNAvar probeAnchor = mainMeshRenderer.probeAnchor;#endif...
#if !UNITY_LUNAmr.motionVectorGenerationMode = motionVectorGenerationMode;#endif...
#if !UNITY_LUNAmr.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.