iron59

  • 18 sept. 2018
  • Inscrit 10 juil. 2015
  • Good day. We're implementing an animated animal character made of several skeleton animations assembled with a single game object parent and with some parts parented to and object with bone follower. We add decorations to the monsters through the use of slots and attachments. The code we use are written in the snippet below:

    public void SetDeco(Color decoColor, string attachmentPrefix) {
         foreach(Spine.Slot slot in this.spineAnim.Skeleton.Slots) {
             if(slot.Data.Name.StartsWith(BodyPartFactory.DECO_SLOT_PREFIX)) {
                 Spine.Attachment attachment = GetAttachment(attachmentPrefix);
                 slot.Attachment = attachment;
                 slot.SetColor(decoColor);
             }
         }
     }
    
     public Spine.Attachment GetAttachment(string attachmentPrefix) {
         Spine.Attachment emptyAttachment = null;
         Spine.Attachment newAttachment = null;
         Spine.Skin skin = this.spineAnim.Skeleton.Skin;
    
     if(skin == null) {
         skin = this.spineAnim.Skeleton.Data.DefaultSkin;
     }
    
     foreach(KeyValuePair<Spine.Skin.AttachmentKeyTuple, Spine.Attachment> attachment in skin.Attachments) {
         if(attachment.Value.Name.StartsWith(attachmentPrefix)) {
             if(attachment.Value.Name == BodyPartFactory.DECO_ATTACHMENT_EMPTY) {
                 emptyAttachment = attachment.Value;
             }
             else if(attachment.Value.Name.StartsWith(attachmentPrefix)) {
                 newAttachment = attachment.Value;
             }
         }
     }
    
     if(newAttachment == null) {
         newAttachment = emptyAttachment;
     }
    
     return newAttachment;
     }
    
    

    Some slots have deco on its name to identify that this slot is meant for the decoration. The attachment prefix is the name of the attachment that should be visible (only one decoration should be used per body part. However, the position of the decorations don't seem to match with the one in the spine editor.

    The slots and attachments for a body part will look something like this.

    Basically what I want to do is select the attachment that needs to be enabled for a particular slot. Any suggestions on how to add the attachment to the slot without incorrect positions? Thank you.

  • Yup. Setting the MixTime solved it. Thank you so much for the help. 🙂

  • I'm trying to pause the animation of a SkeletonAnimation object at a particular frame. What I did first was to set the animation using the following code:

    this.spineAnim.state.SetAnimation(0, animName, loop).TimeScale = speed;

    After this I pause the animation by setting the TimeScale property of the SkeletonAnimation to 0. And then I set the time of the track entry using the following code.

    Spine.TrackEntry trackEntry = this.spineAnim.state.GetCurrent(0);
    
    // QQQ
    Debug.LogWarning(this.itemCode + " Seek Time: " + seekTime.ToString());
    Debug.LogWarning("Before - " + trackEntry.Animation.Name + " Duration: " + trackEntry.Animation.Duration.ToString() + " Time: " + trackEntry.AnimationTime);
    
    trackEntry.TrackTime = seekTime;
    
    // QQQ
    Debug.LogWarning("After - " + trackEntry.Animation.Name + " Duration: " + trackEntry.Animation.Duration.ToString() + " Time: " + trackEntry.AnimationTime);
    
    

    However, the pose of the spine animation did not change. When I traced the spine animation I get this:

    arm4 Seek Time: 2
    Before - idle Duration: 2 Time: 0
    After - idle Duration: 2 Time: 0
    

    Any suggestions on how to fix this? Thank you very much.

  • Okay thank you. Sorry I thought this was the right place to post about the updates.

  • Good day. I'm using the Reset funtion of the SkeletonAnimation to refresh my SkeletonAnimation objects in the scene when I update their SkeletonDataAsset via code. After updating to the latest package, the function seems to not recognized anymore. Any workaround for this? Thank you very much.

    P.S. The SetColor function of Spine.Skeleton is not recognized too, though I just used the A,R,G,B properties of the said class, but it makes my code 4 lines longer when replacing each SetColor function 🙁

  • Understood. Even though this is not the source of the bottleneck, this will still be helpful for optimizing our project. Thank you.

  • Hi Pharan. Can you please clarify the part about all the properties, including the ones that didn't need to be keyed? Our artist is not sure if he understands it correctly. He also said that if you are referring to the move/rotate/scale keys, he said it's the standard practice for keyframe animations, especially when we expect an animation to be cutoff at any given frame, so that the tweening from the first animation to the next animation will not go wonky.

    If possible, could you please send a screenshot of the sample timeline that can be removed?

    Again thank you for the assistance.

  • Link sent. Thanks!

  • Pharan a écrit

    The one above has SkeletonAnimation.Update at 226ms, and a bunch of Spine-unrelated things under it.
    UIWidget? TextPromptFader? GameObject.Activate? what are these things? Somehow, I think you're hooking these things up to Spine skeletons.

    Just from this, I'm suspecting that there's nothing wrong with your animations at all.

    Those are UI functions that I scripted, and they involve NGUI objects.

    I'm considering this possibility as well, so it's kinda frustrating that I can't use deep profile for the device build. I'm just depending on mapping the deep profile when I run the game in the editor, and I happen to see this call to "Apply" function with a considerably high CPU usage. I'll upload a sample spine project for our character. If it's okay, maybe you guys can suggest improvements based on this. Thank you.

  • Thanks for the replies. Based on your suggestions, I'll check:

    • Number of timelines used in the skeletons and try to reduce them if possible
    • Check for color tweens done in spine

    My artist teammate is the one doing the animations and what I only see is the output prefab and json files, so not sure how they're built in spine. I'll check. Thank you very much. Any additional suggestions are very welcome. 🙂

  • Good day. I'm in the process of optimizing our game and I use the Unity profiler to observe the CPU usage. I observed that the SkeletonAnimation.Update at times create spike.

    Since there's no way to deep profile the Android build, I used deep profilin in the editor instead and traced the hierarchy further. It seems the bulk of the executin time can be seen in Animation.Apply()

    I was just wondering if there's a way to optimize this part? I'm considering it could be done on my scripts' end for it is possible that I'm not using the skeleton animations efficiently. Thank you very much.

  • Thank you very much. I should've reported this sooner. I was trying to figure out what step did I miss when I imported the project. It works fine now. 😃

  • I'm currently using Unity 5.3.1f1. When I try to enable tk2d using the references, I get the following error:

    PlayerSettings Validation: Requested build target group (0) doesn't exist; #define symbols for scripting won't be added.
    UnityEditor.PlayerSettings:SetScriptingDefineSymbolsForGroup(BuildTargetGroup, String)
    SpineEditorUtilities:EnableTK2D() (at Assets/spine-unity/Editor/SpineEditorUtilities.cs:1146)
    SpineEditorUtilities😛referencesGUI() (at Assets/spine-unity/Editor/SpineEditorUtilities.cs:1125)
    UnityEditor.HostView😮nGUI()

    With this, the json files in spine are not detected to prompt for a new SkeletonDataAsset. Any suggestions for this? Thank you very much. 🙂

    • Modifié
  • Good day. I'm adding a BoundingBoxFollower component via script using the AddComponent function of Unity.

    public void RefreshCollider() {
          if(this.follower != null) {
             Destroy(this.follower);
          }
    
      this.follower = this.gameObject.AddComponent<BoundingBoxFollower>();
      this.follower.slotName = "CharBounds";
    }
    

    I set the slot name after calling the said function. I was able to get the bounds of the slot name that I specified. However, I have more than one bounding box in my spine animation and I need to get the bounds of another one (apart from the specified slot name) because I need to place a separate game object in it. I tried accessing the colliderTable and attachmentNameTable attributes but it's only retrieving the "CharBounds" bounding box and nothing else. I can verify that the other bounding boxes can be accessed in the inspector. Any suggestions on how to resolve this? Thank you very much. 🙂