• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code Does GMS2 support Spine Inverse Kinematics?

T

ted234521

Guest
Title says it all. When manipulating bones with functions such as bone_state_set (changing a bone's angle to track the mouse, for example), are IK constraints in Spine respected?

In my game I have a character holding a gun with two hands. In Spine, I want to constrain the secondary arm (holding the grip) to the gun so it will angle itself correctly when aiming. If I do this, will game maker correctly position the other bones as I manipulate the other arm?
 

Didjynn

Member
Well yes they say so but then I wonder why it's not working with me. I created the ik constraints in Spine and made my animations with it. But in game maker my legs have the wrong orientation, this is really annoying. I don't know what to do to fix that and I would like to avoid to fix it by code for my 25 different animations
 

rIKmAN

Member
It doesn't. I thought so, and was told so, and bought Spine, only to find out that it doesn't.

https://forum.yoyogames.com/index.php?threads/how-well-is-spine-supported.13822/

EDIT: oh, it was already posted.

Short answer: You can export animations made with IK in spine. But the IK do NOT work inside of GM (you can't set a "hand" bone to a location and see the IK solve the arms)
Did you update to Spine Pro?
If I'm remembering right from the other thread when you were saying IK didn't work you were using Spine Essentials and hadn't setup any IK at all - because you can't in Essentials and which is why it didn't work.

I haven't got around to re-exporting this old rig using Spine 3.7 and testing the skeleton in v2.2.2 yet, but you can see in this example that I'm moving around an IK target bone via code to follow the mouse and the IK for the legs is being solved.

This is inside GMS2... 2.0 or 2.1 I think - I'd have to check when I get home as this was a long time ago now.


Here's the same skeleton where I'm moving the hand IK target with the mouse, and the arm is bending as expected.


There were some other issues I had pre 3.7 runtime update with IK, but not anything that stopped it from working completely - it just didn't work quite right and those same examples I tested in v2.2.2 then did work correctly.

There have definitely been some fixes / changes made during the 3.7 runtime update which I think could make things go a bit wonky if not re-exported from 3.7.

If I can find it I'll test the rig from the gifs above as soon as I can find some time and make sure they still work as expected.
 
Last edited:

Didjynn

Member
I actually have the pro version.

Everything is nice and well in Spine.



Here you can see Spine on the left and Game Maker on the right, the "foot" are going up or down and they always keep this inclinaison. I really have no idea why, IK constraints are used between the foot and the leg, the foot just have a fixed rotation (so they are always perprendicular to the ground. They do not inherit from the leg's orientation but I don't think this is linked to the problem since when it plays the animations, the foot still keep this position
 

Didjynn

Member
I got my answer from Spine's forum :

The bad part about this is that GameMaker is in sync with an older version of Spine, where the latest things like IK stretch, or disabling inherit scale/rotation, and others aren't available for you to use. The good thing is that they should be in the process of updating their runtime.
 

rIKmAN

Member
I got my answer from Spine's forum :

The bad part about this is that GameMaker is in sync with an older version of Spine, where the latest things like IK stretch, or disabling inherit scale/rotation, and others aren't available for you to use. The good thing is that they should be in the process of updating their runtime.
How old was the post you found that information in?

The example skeleton that comes with Spine 3.7 that uses stretchy squashy IK runs fine (ie. just as it looks in the Spine IDE) in the latest version of GMS2 by just exporting from Spine and loading into GMS2. If it wasn't supported I would expect that example to fail.

It can be found in your Spine folder: \examples\stretchyman\stretchyman-stretchy-ik-pro.spine
You obviously need Spine Pro for access to the IK features.
 

Didjynn

Member
I got this answer in the last 24 hours from Spine's staff.

My problem isn't IK finally but the inheritance of rotation, I unchecked it to keep my foot in the right position for the ground.
 

rIKmAN

Member
I got this answer in the last 24 hours from Spine's staff.

My problem isn't IK finally but the inheritance of rotation, I unchecked it to keep my foot in the right position for the ground.
It sounds like maybe the staff member you spoke to isn't aware that GMS2 has been updated to use the 3.7 runtimes, as they are the latest runtimes.
I did get a similar response myself a while back, but that was when GMS2 used the 3.4 runtimes so that info was correct then.

Is your problem solved now or do you still have the issue with rotation / inheritance?

If you still have it, post the issue in the Spine Update 2.2.2 feedback thread and tag Dan to hopefully get an answer.
YYG are the only ones that can really answer how things such as that have been implemented into GMS2 on the back end.
 

Didjynn

Member
Sooo I'm back on this thread because I was right about the GMS2 update :p

Just kidding, I'm back here because I still have some troubles with the spine animations in GMS2. You did some in real time animations and it looks great, I would like to do that too but I don't understand which line of code I should use... maybe I missed it but I find no code line to move a bone. Can you tell me that please ?
 

rIKmAN

Member
Sooo I'm back on this thread because I was right about the GMS2 update :p

Just kidding, I'm back here because I still have some troubles with the spine animations in GMS2. You did some in real time animations and it looks great, I would like to do that too but I don't understand which line of code I should use... maybe I missed it but I find no code line to move a bone. Can you tell me that please ?
If you check the skeleton animations section of the manual all the functions you can use to access and modify skeleton properties are listed there.

To modify bone properties you use the following:
skeleton_bone_state_get()
skeleton_bone_state_set()
skeleton_bone_data_get()
skeleton_bone_data_set()

Make sure the read the manual for the slight differences between them and which one you want to use, as one uses the current frame of the skeleton and one uses the setup pose of the skeleton.

There is example code at the bottom of those pages of how to get and set the properties of a bone.
 

Didjynn

Member
ahhh okay thanks. I did read these but I did not understand it was permitting me to do that... Thanks again !
 

DukeSoft

Member
Please note that it does support IK now, but only 2 bones. If you want a hand, lower arm and upper arm, it doesn't work. Spine doesn't support multiple constraints..
 

rIKmAN

Member
Please note that it does support IK now, but only 2 bones. If you want a hand, lower arm and upper arm, it doesn't work. Spine doesn't support multiple constraints..
It also supported IK the last time you claimed it didn't, it's just that you were using Essentials and IK is Pro feature.

Not exactly sure what you mean by hand, lower arm and upper arm not working with IK?
Have you actually tested this in Pro?

Unless I'm misunderstanding you, then there are many examples of that (or a similar) setup working with IK, I posted one above with the cyborgs legs reacting to an IK bone being moved with the mouse.

I'm not sure how that was setup inside Spine as I'd have to dig out the project file (I didn't make it) but there are clearly more than 2 bones in the legs reacting via IK from the foot up to the hip, which is what you are saying isn't possible with a hand / lower arm / upper arm setup.
 

DukeSoft

Member
Hey @rIKmAN,

No, I actually bought Pro and tried to make a setup for a top down player: root (neck) -> left shoulder (static) -> upper arm -> lower arm -> hand.

I wanted the arm and hand to move using IK constraints - and wasn't able to do so in Spine. When asking how I could achieve this, this is the response I got from the team at spine:
Sorry for the late reply. Indeed, Spine only supports 2 bone IK. However, you apply apply multiple constraints to the same bone, e.g. an IK constraint plus a transform constraint
 

rIKmAN

Member
However, you apply apply multiple constraints to the same bone, e.g. an IK constraint plus a transform constraint
Is that meant to say "you can apply"?

If so then maybe that's what you need to do to get the results you are after and also maybe the way it was setup in the gif I posted of the legs, as that seems like it is exactly what you are trying to achieve except with arms (ie. multiple bones ( >2) reacting when setting a target IK bones position to the mouse position using the skeleton_bone_* functions)

There are definitely ways to get the setup you were were trying achieve even with the 2 bone IK system that Spine has in place - this section of this video shows how you can join multiple 2 bone contraints together for example - and I'm sure there are other methods to achieve the same goal.
 
Last edited:

DukeSoft

Member
Hmm.. What I wanted to accomplish might indeed be that - I just know that Spine IDE gave me errors when I tried to add multiple constraints (something about bones already connected or something like that) - I wanted to only move the hand (actually the weapon in the hand), and make sure the elbow always gets pushed outwards while the hand also has a constraint on a 90 degree angle. And then the same for the other arm + hand.

I just kinda gave up on it and am working on my own IK, and I don't feel like buying Spine Pro again for only this one time purpose.
 

rIKmAN

Member
Hmm.. What I wanted to accomplish might indeed be that - I just know that Spine IDE gave me errors when I tried to add multiple constraints (something about bones already connected or something like that) - I wanted to only move the hand (actually the weapon in the hand), and make sure the elbow always gets pushed outwards while the hand also has a constraint on a 90 degree angle. And then the same for the other arm + hand.

I just kinda gave up on it and am working on my own IK, and I don't feel like buying Spine Pro again for only this one time purpose.
As I said I'd have to look at the project file for the cyborg skeleton as it was done by someone else when they were learning Spine, so if I can find it I'll take a look and see.

Probably too late now but it might have been worth jumping on the Spine Discord and asking there, Erikari is active there and is really helpful - she does all the Spine tutorials / streams on the Esoteric Twitch Channel and knows her stuff.

If you already bought Pro you don't need to buy the licence again, it's a lifetime licence not a subscription.

edit:
Forgot to mention the runtime made by Nux might be worth you taking a look at also as that may be helpful to you.
 
Last edited:

DukeSoft

Member
Hey rIKmAN,

Thanks! Yeah I actually requested a refund because that was the sole reason I bought it, and the friendly folks from Esoteric refunded the program to me, so unfortunately I don't have the possibility to try it anymore.

I did see Nux's stuff indeed, looked very promising.

Maybe next time if I have to deal with IK and Spine again I'll give it another shot :)
 

Imershard

Member
Did you update to Spine Pro?
If I'm remembering right from the other thread when you were saying IK didn't work you were using Spine Essentials and hadn't setup any IK at all - because you can't in Essentials and which is why it didn't work.

I haven't got around to re-exporting this old rig using Spine 3.7 and testing the skeleton in v2.2.2 yet, but you can see in this example that I'm moving around an IK target bone via code to follow the mouse and the IK for the legs is being solved.

This is inside GMS2... 2.0 or 2.1 I think - I'd have to check when I get home as this was a long time ago now.


Here's the same skeleton where I'm moving the hand IK target with the mouse, and the arm is bending as expected.


There were some other issues I had pre 3.7 runtime update with IK, but not anything that stopped it from working completely - it just didn't work quite right and those same examples I tested in v2.2.2 then did work correctly.

There have definitely been some fixes / changes made during the 3.7 runtime update which I think could make things go a bit wonky if not re-exported from 3.7.

If I can find it I'll test the rig from the gifs above as soon as I can find some time and make sure they still work as expected.

Hello, I was wondering how this could be set-up in Spine? You said you moved "around an IK target bone" I'd love to know how to do this.

I've successfully manipulated bones in Gamemaker with "skeleton_bone_state_set", but the moment I use that function on an IK bone or a parent bone with a child IK bone, Gamemaker gives a "DoSub :1: undefined value".

Is there a way I can reference IK bones in Gamemaker?
 

rIKmAN

Member
Hello, I was wondering how this could be set-up in Spine? You said you moved "around an IK target bone" I'd love to know how to do this.

I've successfully manipulated bones in Gamemaker with "skeleton_bone_state_set", but the moment I use that function on an IK bone or a parent bone with a child IK bone, Gamemaker gives a "DoSub :1: undefined value".

Is there a way I can reference IK bones in Gamemaker?
You reference an IK bone just like you would a "regular" non-IK bone, the only difference is that you have rigged the IK correctly in Spine so that when you move whatever bone the other bones in the IK chain you have setup inside Spine will then act/react just how they do in the Spine IDE when you test the IK there.

There were issues with IK and GM ages ago but they were fixed a while back so as long as you correctly setup IK inside Spine, export v4.0 json into GM and then reference the correct bones then all should act/react accordingly.
 

Imershard

Member
Thanks for the extremely quick response!

I'm exporting using Spine version 4.0 and using the latest Gamemaker 2 version.

I'm going to try to ask a better question:

From my understanding, in Spine, there are three kinds of bones.
The IK bone that looks like this:
Cool - Copy.png

The normal bone that looks like this (above the IK bone):
Very Cool - Copy.png

And then the bones that are affected by IK:
Quite Possibly The Coolest - Copy.png

I have a block of code that works when I reference the "Up L arm" bone, but doesn't work for either of the other two bones.

In spine, when I play the animation it looks fine.

In Gamemaker I tried two different methods.
Method One: referencing the IK bone without a parent.
Method Two: referencing a parent bone of the IK bone.
Both give the "DoSub :1: undefined value" error.

When I first purchased Spine Pro, I think I remember getting this error when I referenced images from Spine, but then I didn't get the error when I started referencing bones. - just putting this here for more info.

But now I'm referencing those IK bones.

I make no changes to my code other than changing the referenced name of the bone.
For example:

skeleton_bone_state_get("Up L arm ", map); //WORKS

skeleton_bone_state_get("Front Arm IK Bone", map); //DOES NOT WORK

skeleton_bone_state_get("Front Arm IK", map); //ALSO DOES NOT WORK


Just in case it helps, here is the code I'm using:
In Gamemaker, I'm using an object's "Animation Update" event with the following code:

//CODE START

GML:
targetx = mouse_x
targety = mouse_y


var map = ds_map_create();

skeleton_bone_state_get("Front Arm IK Bone", map);

var xx = ds_map_find_value(map, "worldX");

var yy = ds_map_find_value(map, "worldY");

var deltax = targetx - (xx);

var deltay = targety - (yy);

if sign(image_xscale) = 1{ // facing right

    var angle = (-radtodeg(arctan2(deltay, deltax)))-90;

}

if sign(image_xscale) = -1{ // facing left

    var angle = (radtodeg(arctan2(deltay, deltax)))+90;

}

ds_map_replace(map, "angle", angle);

skeleton_bone_state_set("Front Arm IK Bone", map);

ds_map_destroy(map);
//CODE END
 

rIKmAN

Member
@Imershard
Have you correctly setup the IK constraints?
How many do you have? (3 or more are not supported)
What is the exact DoSub error message?
What version of GM are you using?

I'd make a small test project with just a limb setup with IK and constraints and get that working by just having the target bone be positioned at the mouse x/y position.
Once you get that working you can extrapolate out and use the same method to get the other limbs working in your main project.

Also have a read of the IK Constraints section of the Spine manual to make sure you've got everythign setup correctly on that side first of all, I have a feeling you've missed a step or got something slightly wrong there.
That can be found here: https://en.esotericsoftware.com/spine-ik-constraints

There are also some IK example projects linked in there that you should checkout as well to see how they are setup inside Spine.
Then export those to GM and try setting the IK Target bones to the mouse position and seeing if they work.

I'll see if I can dig out the old project I had when I was playing around with IK, but I might only have gifs left as it was on an old hard drive.
I definitely don't remember doing any funky maths or using arctan/radtodeg etc - from memory it was simply setting the IK Target to the mouse position and everything reacted accordingly but it was a long time ago!

Just found these on my Imgur which were from the posing tool project I was playing with back then.
1) Arm IK in Spine
2) Leg IK in Spine
3) Limb IK inside GM

You can see in GM when moving by the regular "non-IK" pelvis bone that the arms/legs still respect the IK Target(s) regardless of it's position and point to where they are until the IK Targets are specifically moved.
Moving the arms/legs repositions the IK Target bones and the limbs follow as they should based on that new position.

It's possible a bug has been reintroduced since back then, but it worked fine at the time so do some testing as above and see how you get on in a simpler project where you are sure everything is correctly setup.
 

rIKmAN

Member
Hey, where does that info come from? I've tried to find any reference to it.
It's imposed on the Spine side, it's not an limitation enforced by GM.

Have a read through the Spine docs on IK Constraints which at the bottom of the "Setup" section says:
Constraining three or more bones is not supported because it is nondeterministic and would be difficult to control. Instead, use multiple IK constraints or FK.
 
Ah, yes. It means that you can't connect three bones in one IK constraint.

I thought that in your previous reply you meant that "you can't have three or more separate IK constraints in one animation", and got confused about it.
 

rIKmAN

Member
Ah, yes. It means that you can't connect three bones in one IK constraint.
Yep, exactly that.
I thought that in your previous reply you meant that "you can't have three or more separate IK constraints in one animation", and got confused about it.
Ah, no I didn't mean that but I can see how it might've read that way.

I meant no more than 3 constraints in a single IK chain as per the manual.
 

Imershard

Member
@rIKmAN

Apologies for my long hiatus. I just wanted to come back and say that my error from before was me being a goober, I was referencing bones that didn't exist.

Now I'm using the correct names. I wanted to come back and thank you. Your assistance with spine on the forum posts has lead me to create some very satisfying movement in my game projects!

:)


Also just want to put here what I found out about the "DoSub :1: undefined value" error.
Here is what the error looks like:
oh_no_it's_the_DoSub.png

It looks like this error pops up when you don't reference a spine bone. I also got this error when I referenced a spine IMAGE. So only reference BONES. I messed that up 🤦‍♂️
 
Last edited:
Top