• RuntimesUnity
  • Spine 4.2 Physics - General Questions

Hey Harald and everyone, hope your holidays & New Year went well!

I finally got the chance to take a look at the 'issue' I had mentioned in my post a month ago. Turns out it seems to all boil down to one thing - not understanding how the "wind" and "gravity" values that are set/keyed in a Spine animation get translated to how they actually appear in Unity. Note: I did most of my testing with "wind" and not "gravity" so I'll just focus on "wind" since I think they operate in a similar fashion.

In my test project I set up a hanging banner (like a flag) that hangs straight downward. It's mesh is bound to a chain of bones. I created an animation that has a single key, which is the "Wind" being set to 30.

  • In Spine, the Wind value causes the banner to be rotated clockwise over 45 degrees (so its pointing towards the right)
  • However, in Unity the banner is barely angled at all. It's basically pointing straight downward.

I noticed that if I cranked up the Wind to a ridiculous value, it did affect how it looked in Unity, but way less, as though it was scaled down a bunch. So I thought it might be something related to "unit values" (ie. Spine units versus Unity units, or something like that). I tried changing the "Scale" on the SkeletonData.asset from the default value of 0.01 to 1. This did indeed help (how it looked in Unity became closer to how it looks in Spine), but it still isn't correct. It was still off by a factor of 2, or something around that.

  1. Is there some sort of "unit-value scaling" that I need to set on the Unity project to make it look the same in Unity as it does in Spine?
  2. Once I get question #1 figured out, I'd like to be able to test out applying my own Wind to SkeletonAnimations though code. Any tips on how this can be done? Ultimately what I'd like to test out is setting up my weather system in-game where it sets the Wind value on the SkeletonAnimation based on the position of the character in-game (aka each frame my weather system would calculate how strong the wind is at the location the character is standing, and apply it to the SkeletonAnimation). My ultimate goal is to have my weather system handle in-game gusts of wind, etc, including temporary bursts of wind from other characters doing things like slamming their weapon down on the ground nearby 😃
  3. Just wanted to check - is there any documentation for physics with either the Spine Editor of the Unity Runtime? Guessing not since it's still beta and is still changing, but just want to verify since right now I'm learning purely by testing 😄

Thanks for any help!

Related Discussions
...

There is a typo in my post (supposed to say "...either the Spine Editor or the Unity Runtime") but I can't seem to edit the post? I don't remember where the Edit button is supposed to be, but I've been looking for 5 minutes and either it's not there or I'm going crazy, lol

Edit: I can edit this reply, but not my original post?

Screenshot of the "..." button next to my Reply:

Screenshot of my original post, with no "..." button?

Is there a time limit on how long you have to edit your post/reply? I can't edit any of my old posts/replies.

Yes, posts can only be edited for 10-15 minutes after posting.

Physics is affected by bone lengths. It sounds like there is a bug where data loading scale is not being applied in a way that results in the same physics behavior at different scales. We'll take a closer look at it and get back to you!

    Nate Heya Nate, thanks for the info/answer! Sounds good, if you guys happen to need any additional info just let me know.

    • A Nate le gusta esto.
    7 días más tarde

    Harald Hey Harald!

    I updated with that version, and unfortunately it didn't fix the issue. I just emailed a zip of my Spine project to contact@esotericsoftware.com. In the project there are a couple different pieces, since I was testing things out. The issue happens with this bone, which is the only one that uses the physics constraint for "Translate X/Y". When I set that physics constraint for Translate X/Y back to 0, it fixes the issue.

    The issue is that, in Unity, the bone goes way out to the side, something like 200x further than it should in the animation.

    To repro:
    1) Export/import the project into spine
    2) Create new SkeletonAnimation by dragging the SkeletonData asset into the scene
    3) Set the SkeletonAnimation to use the animation called "wind animated"
    4) Run the scene and observe that the bone goes way further to the right than it does when you play the "wind animated" animation in Spine.

    As mentioned above, changing the "scale" on the SkeletonData asset itself (the one that is by default 0.01) seemed to affect it, so I'm wondering if its some sort of conversion from Spine units to Unity units, or something like that 🤔

    Thanks for checking it out and let me know if I can provide any more info or anything!

    Oh dear, sorry to hear that the issue persists! Thanks for the repro project, we'll reply here on the forum as soon as we've figured out what's going wrong.

    @Jamez0r We have just pushed a bugfix to the 4.2-beta repo, it turned out that load scale (import scale in Unity) was ignored, affecting wind and gravity. A new spine-unity 4.2-beta unitypackage is available for download:
    https://esotericsoftware.com/spine-unity-download
    Please let us know if this now fixes the issues on your end as well. Thanks again for reporting!

    Issue ticket for later reference:
    EsotericSoftware/spine-runtimes2446

      Harald Woohoo! That fixed all of the issues we had that were physics-related. Thanks!

      There is only one more issue that we're experiencing with 4.2, which I wasn't sure if it was related to that physics-issue you just fixed or not so I hadn't mentioned it.

      The problem is with an IK constraint for this Woodsman character's elbow. We've used rigs like this before, so we think its an issue specifically with 4.2. I just sent you a zip of the spine project (I replied to the email response you sent me earlier today). There is an animation called responses/technique/default/4.release. This animation has the character's claw-arm raise upward, and at a certain point when he is raising it up, an IK constraint on his arm is keyed to go from "Options: Positive: True" to "Options: Positive: False" (the checkbox).

      In Spine, this looks as intended.

      In Unity, the arm's elbow flips out, almost as though the "Options: Positive" value is being toggled every frame (just a guess, thats kind of what it looks like)

      I took the original responses/technique/default/4.release animation and deleted all of the keys except the ones for that claw-arm and named it responses/technique/default/4.release (ARM ONLY - IK ISSUE) to make it easier to see the issue.

      Steps to repro: Export the project from Spine to Unity, create a new SkeletonAnimation with it, and set its default animation to the responses/technique/default/4.release (ARM ONLY - IK ISSUE) animation. Observe that the elbow goes wild during the animation.

      Unity version 2022.3.12f1
      Spine-Unity Runtime: Package version: spine-unity-4.2-2024-01-11-beta.unitypackage

      • It seems like the issue happens during the time period in the animation when the IK: Arm_Right_IK is set to Option: Positive: False, which starts on frame 3 of the animation.

      Let me know if I can provide any more info, or if you want me to start a separate thread or submit an official bug report or anything. This is the only remaining issue we're having with 4.2, so we're pretty stoked!

      @Jamez0r Glad to hear the updated fixed your physics-related issues, thanks for the feedback!

      Sorry to hear that another issue remains, thanks for the reproduction project. We'll have a look at it and get back to you here on the forum as always. Thanks for reporting!

      Harald Its working!!

      Thanks Harald, you rock! Now to play around with all the physics stuff some more 🙂

      Quick question just to point me in the right direction here - in regards to question #2 on my original post in this thread, is there a way to programmatically set the (global) wind/gravity values for a SkeletonAnimation? I might mess around with testing out that wind system I mentioned sometime soon 😃

      • A Nate le gusta esto.

      Everything is possible programmatically. 🙂

      You can just set the wind and gravity values on the physics constraints directly. If you key the physics constraints' wind and gravity, you'd need to modify the values after you apply animations.

      If you would rather use an animation, you'd have to create a new animation and timelines or dig through an existing animation's timelines to find the wind and gravity timelines, then you can change the keyed values, add/delete keys, etc on the wind and gravity timelines. Note that by default the animations are shared by all skeleton instances, so you'd need to duplicate the animation if you don't want your changes to affect other skeleton instances.

        Nate Hey Nate, thanks for the info!

        What I'm looking to try out is not having wind or gravity keyed in any animation on the character, but instead having my own weather system in Unity determine "how windy it should be" each frame at the location each spine-character is standing, and then apply that value to the SkeletonAnimation somehow. Imagine a grassy field with characters sprinkled around in it, and my weather system handles calculating the "wind value" for each character as gusts of wind blow across the field.

        If I knew "at this moment in time, the wind value for this character at this location should be 2.5", how could I most easily apply that to the SkeletonAnimation for that character? You mentioned being able to set the wind/gravity values on the physics constraints directly, so would that be the best to do it? Meaning I need to aggregate a list of the physics constraints, and iterate through them applying the wind value (rather than doing it at some "global" level that automatically affects all of them)?

        Thanks for the info!

        Yep, just set all the physics constraints' wind and gravity. Super easy!

        There is no "global" setting. The global timelines just set the value for multiple constraints.

          Nate Thanks Nate!

          Would like to use physics constraints' wind and gravity programmatically in the future. My head is still wrapped around trying have Spine-Cpp and Godot-Gdscript play nice 😑.

          I think we've been experiencing something similar, we're using todays update which fixed some other issues we had but we're suffering a leaning issue that differs between Spine and Unity much like this

          100 gravity on the right shoulder strap in Unity at the end of the Angry animation

          100 gravity on the right shoulder strap in Spine editor at the end of the Angry animation

          0 gravity in Spine Editor, the right shoulder strap veers further to the left much like in the Unity scene

          I've sent the spine file and a blank unity project with just this scene and spine already configured to show the issue to contact@esotericsoftware.com, just hit play in the unity project and you'll see the difference.

          Edit: just noticed the clip accessory on the weapon is also exhibiting this if that helps!

          @bantam Sorry to hear you've encountered problems, thanks for reporting! This sounds like the bug with wind and gravity which has been fixed just 4 days ago:
          EsotericSoftware/spine-runtimes2446 (via this commit)
          Could you please have a try whether the very latest spine-unity package resolves the issue on your end?

            Harald

            Thanks for responding, I may have I have missed a step to make it work, do we need to programmatically provide a gravity level in Unity somewhere? I didn't see a method for it through the SkeletonAnimation api.

            Downloaded and run with spine-unity 4.2-beta (updated 2024-01-12), if it's not this version please let me know I will test again. I think it is correct though as I see the changes in the source.

            I added a couple of break points to see if it hits those changes and it does, it seems to be applying gravity to the data structure.

            Seems to make it to PhysicsConstraint.cs constructor

            makes it down here

            Also tried it with another one of our spines that uses 100 gravity for hair with a test pose to make it more obvious, 2023 blank project with default unity settings with SkeletonAnimation pulled into an otherwise blank scene to make sure its not any of our current projects settings screwing things up.

            Hair not applying gravity

            100 Gravity hair successfully working in Spine Editor

            These gravities are set up in the setup pose in editor not in the animation timeline if that helps.

            P.S. these physics constraints have really been impressive! It's a game changer for our productivity.