Hi, I have a character with multiple facial expressions that I'd like to control in Unity. One of the concerns I have is with the eye blinking animation. In addition, there are other eye expressions like looking up, down, frowning, etc. For certain eye expressions, blinking should not be mixed with them.

To summarize:

  • Blinking (animation)

  • Eye Expressions (Skins):

  • - Eye Expression 1

  • - Eye Expression 2

  • - Eye Expression 3 (should not be mixed with blinking)

  • - Eye Expression 4 (should not be mixed with blinking)

Given this setup, what’s the best way to organize the skins?

Related Discussions
...

To manage multiple facial expressions and control them effectively in Unity, you can use a combination of skins and animations. Here’s a structured approach based on the provided contexts:

  1. Use Skins for Eye Expressions:

    • Create separate skins for each eye expression (e.g., Eye Expression 1, Eye Expression 2, etc.).
    • Ensure that the skins are named consistently to facilitate easy switching at runtime.
  2. Isolate Blinking Animation:

    • Create a separate animation for blinking that only affects the eyes. This can be done by keyframing only the eye attachments and not other body parts.
    • Use a higher track in Unity to play the blinking animation on top of other animations. This allows you to control when blinking occurs independently of other animations.
  3. Conditional Blinking:

    • For eye expressions that should not be mixed with blinking (e.g., Eye Expression 3 and 4), you can control this in Unity by checking the current skin before playing the blinking animation.
    • Implement logic in your Unity script to prevent the blinking animation from playing when these specific eye expressions are active.
  4. Combining Skins at Runtime:

    • Use the Skin.addSkin method to combine multiple skins if needed. For example, you can combine a base skin with an eye expression skin.
    • Refer to the Combining Skins section in the spine-unity runtime documentation for detailed code examples.
  5. Linked Meshes for Consistency:

    • Use linked meshes to ensure that the same meshes and weights are reused across different skins. This helps maintain consistency and simplifies management.

Here’s a brief example of how you might set this up in Unity:

// Assuming you have references to your skeleton and animation state
Skeleton skeleton = skeletonAnimation.Skeleton;
AnimationState state = skeletonAnimation.AnimationState;

// Function to switch eye expression
void SetEyeExpression(string expressionSkinName) {
    Skin newSkin = new Skin("combined");
    newSkin.AddSkin(skeleton.Data.FindSkin("baseSkin"));
    newSkin.AddSkin(skeleton.Data.FindSkin(expressionSkinName));
    skeleton.SetSkin(newSkin);
    skeleton.SetSlotsToSetupPose();
}

// Function to play blinking animation conditionally
void PlayBlinkingAnimation() {
    string currentEyeExpression = GetCurrentEyeExpression();
    if (currentEyeExpression != "Eye Expression 3" && currentEyeExpression != "Eye Expression 4") {
        state.SetAnimation(1, "blink", true);
    }
}

// Example usage
SetEyeExpression("Eye Expression 1");
PlayBlinkingAnimation();

This approach ensures that you can manage multiple facial expressions and control blinking effectively without unwanted overlaps.

  • A acai le gusta esto.

Thanks Spinebot!

    acai The way Spinebot suggested would probably work, but if I were you, I would accomplish this by devising a skeleton setup: If you do blinks by changing attachments, you can assign the same eye attachment to all skin placeholders. This makes it appear as if it is not blinking while the blink animation is played. When you use bones to do blinks, you can set weights to control how much the eye image is affected. For example, a closed eye mesh attachment will not be affected by the blink animation if it has no weight for the bones that create the blink animation.

    Thank you, Misaki! Your advice sounds much more efficient and effective.

    I'm using eye attachments to create a blinking animation, and I just wanted to clarify something since I'm still figuring out the rules in Spine:

    • Could you explain a bit more about what you mean by

    assign the same eye attachment to all skin placeholders

    I thought each placeholder could only have one attachment at a time. (Sorry, I'm still learning.)

    • Also, what’s your opinion on changing facial expressions by mixing animations across multiple tracks?

    Thanks so much for your help!

      acai Sorry for the unclear explanation! I was thinking of a setup like this:

      It is true that only one attachment can be assigned to one skin placeholder. However, if you want the eyes to always be closed even when blink or facial expression animations are played, for example, when the “eyes-closed” skin is assigned, you can assign the same eyes to all skin placeholders in this way and the appearance will remain unchanged.


      Also, what’s your opinion on changing facial expressions by mixing animations across multiple tracks?

      Are you concerned about whether or not it will work to play back multiple facial animation while switching facial expressions with skins? Or do you mean whether it is better not to use skins?
      It is a very common approach to manage facial expressions through animation without skins. The advantage of using skins only to change the appearance of the character and managing facial expressions through animation is that it saves the time and effort of preparing a skin for each facial expression for each character appearance. Also, if each facial part is animated by bones rather than by changing attachments, it might be better to manage them through animations so that the mix can be used, for example, to make a natural transition from an expression with raised eyebrows to one with lowered eyebrows.

      Sorry if this is not what you intended with your question. We may be able to advise you further if you give us more details about the skeleton assumptions you are hoping to achieve.

      • Editado

      Thank you so much for your quick response, Misaki!
      I apologize for not being clear in my initial question. I was asking from a performance perspective, or if there might be any Spine features I’m not aware of. I saw in one of your previous posts that you recommended using Skins for simple facial expressions, so I was curious about your thoughts on that.

      Based on your reply, I'll manage my facial expressions through animations without using skins. I do have one question, though:

      My character is currently set up like this in Unity:
      • Track 0: Idle
      • Track 1: Blinking
      • Track 2: Talking
      I usually use Track 3 for facial expressions. Here's how I have it configured:
      In Spine's Preview, when I mix Idle (Track 0) + Blinking (Track 1) + Facial Expression (Track 3), the blinking animation doesn’t play. But in Unity, it does. Do you think my Spine animation setup might be incorrect?


      Thanks again for all your help!

        [deleted]

        @acai I might be missing some context here, just sharing some potential causes:

        • Is any of your animations set to Mix blend Add mode? The Spine Editor is setting bones to setup pose between frames, while the runtimes are not, so additive tracks (or animations) are different if the lower track does not key the same properties as the additive tracks added on top.
        • Do you perhaps have Animation clean up enabled during export? This removes keys identical to the setup pose and might cause a different result at runtime.

        acai There is a difference between playing animations in the preview view in the Spine editor and playing them in Unity: Spine's preview view does not support non-loop playback (animations are always played in a loop), while in Unity you can apply animations as loop:false, which may have caused this.

        Since you are animating the Eye-Front-Closed slot with both Blink and FE-frowened-ahh, setting FE-frowened-ahh on the upper track in the preview will cause the attachment in the Eye-Front-Closed slot to be hidden repeatedly.
        The mouth animation should not include the slot keys used for the blink animation, so that the mouth animation does not override the blink.

        Thank you so much for your responses!

        Thank you Harald, I didn’t know about the Animation Clean up option. And yes, it was checked. I exported the animation without it, and now the blinking is not happening! Although I’m still not 100% sure why it seems to be working.

        And thank you Misaki! Just to clarify, a higher track (with a bigger number) will override a lower track? So if both animations are using the same keys, only the animation on the higher-numbered track will be visible?

        Thanks again for all your help!

          acai Thank you Harald, I didn’t know about the Animation Clean up option. And yes, it was checked. I exported the animation without it, and now the blinking is not happening! Although I’m still not 100% sure why it seems to be working.

          If your Track 2: Talking animation has keys identical to the setup pose, these will overwrite the lower track's Track 1: Blinking animation. If you export with Animation clean up enabled, the keys in the Talking animation identical to the setup pose will be removed, thus no longer overwriting the lower track.

          If you are using Mix Blend Add on any of the animations, it might be a different reason, but as you didn't mention that you are using Add, I assume that none of your animations is using it.

          Thank you for your quick responses! They've really helped me understand the process better.
          And yes, I haven’t used Mix Blendor Add yet because I’m not too familiar with those features, but I’ll look up some tutorials and give them a try. Thanks again to both of you for your help.