Forum rules - please read before posting.

Spine Pro Save and Load Animations

Hey there,

I'm using spine and the spine animation script. Is it possible to save the spine Animation poses? Because if I'm using constandID and load a save file it get back to the standard idle animation and only save the rotation

Comments

  • It's possible to write custom Remember scripts that you can attach to objects to save specific data - a tutorial can be found here.

    There are a couple of Spine integration scripts out there - which are you using, and what's the exact field you're looking to save?

  • edited June 2022

    Thank you for the fast answer.

    I'm looking for saveing the changed spine animations for exapmple NPC, Player or other 'spine animations'. I'd like to save the changed animation . After loading a save file it switch back to the prerset/default animation

    https://imgur.com/ILGQkY1

  • My biggest problem is I have absolute no programming skills. This is why I use adventure creator and other kind of visual scripting systems like playmaker. If you or anyone could help me I would be very grateful. This would be very awesome!

  • In order to help, I need to know exactly what field you're changing, and how. That is, which Inspector field you want to save, on what component, and how you're updating it using Actions.

    Please share screenshots not of how it appears in-game, but how things are being affected in the Editor.

  • edited June 2022

    thank you very much in anticipation!

    I am changing this: https://imgur.com/63tIv9I with this https://imgur.com/maUygKO, this https://imgur.com/agzVyqn and this https://imgur.com/MnISYHk

  • edited June 2022

    I will look into it.

    You should, however, find that changes made to a character's "Standard" animations are saved - e.g. Idle_setzen. Is this not the case?

  • Awesome!! Thank you very much!

    hm...good question...I've set it to the standard animations but I've realized the state itself is not saved: https://imgur.com/YUa6ccN
    I'm using the 'Remember Transform' and now I've added the 'Remember NPC' script but it still do not save the state. Am I missing something I should add to them?

  • edited June 2022

    It's really a case of what Spine allows for, but give this a try:

    using System;
    using System.Collections.Generic;
    using UnityEngine;
    using Spine.Unity;
    using Spine;
    
    namespace AC.Spine
    {
    
        [RequireComponent (typeof (SkeletonAnimation))]
        public class RememberSpineAnimation : Remember
        {
    
            public override string SaveData ()
            {
                SpineAnimationData spineAnimationData = new SpineAnimationData ();
    
                List<TrackEntryData> trackEntryDatas = new List<TrackEntryData> ();
                SkeletonAnimation skeletonAnimation = GetComponent<SkeletonAnimation> ();
                for (int i = 0; i < skeletonAnimation.state.Tracks.Count; i++)
                {
                    TrackEntry trackEntry = skeletonAnimation.state.GetCurrent (i);
                    if (trackEntry.Animation != null && !string.IsNullOrEmpty (trackEntry.Animation.Name))
                    {
                        trackEntryDatas.Add (new TrackEntryData (i, trackEntry.Animation.Name, trackEntry.Loop));
                    }
                }
    
                spineAnimationData.trackEntryDatas = trackEntryDatas.ToArray ();
                return Serializer.SaveScriptData<SpineAnimationData> (spineAnimationData);
            }
    
    
            public override void LoadData (string stringData)
            {
                SpineAnimationData data = Serializer.LoadScriptData<SpineAnimationData> (stringData);
                if (data == null) return;
                SavePrevented = data.savePrevented; if (savePrevented) return;
    
                SkeletonAnimation skeletonAnimation = GetComponent<SkeletonAnimation> ();
                foreach (TrackEntryData trackEntryData in data.trackEntryDatas)
                {
                    skeletonAnimation.state.SetAnimation (trackEntryData.trackIndex, trackEntryData.animationName, trackEntryData.doLoop);
                }
            }
    
        }
    
    
        [Serializable]
        public class SpineAnimationData : RememberData
        {
    
            public TrackEntryData[] trackEntryDatas;
    
            public SpineAnimationData () { }
    
        }
    
    
        [Serializable]
        public class TrackEntryData
        {
    
            public int trackIndex;
            public string animationName;
            public bool doLoop;
    
            public TrackEntryData (int _trackIndex, string _animationName, bool _doLoop)
            {
                trackIndex = _trackIndex;
                animationName = _animationName;
                doLoop = _doLoop;
            }
    
        }
    
    }
    
  • first thank you very much for helping and wirting a complete script

    I'v added the script to the spine sprite child of the player (lhttps://imgur.com/AMLlLxd). After saving and loading nothing changes. I'v got this error message:
    NullReferenceException: Object reference not set to an instance of an object
    AC.Spine.RememberSpineAnimation.LoadData (System.String stringData) (at Assets/World of Amnesia/RememberSpineAnimation.cs:45)
    AC.LevelStorage.UnloadScriptData (System.Collections.Generic.List`1[T] allScriptData, UnityEngine.SceneManagement.Scene scene) (at Assets/AdventureCreator/Scripts/Save system/LevelStorage.cs:742)
    AC.LevelStorage.LoadSceneData (AC.SingleLevelData levelData, AC.SubScene subScene) (at Assets/AdventureCreator/Scripts/Save system/LevelStorage.cs:411)
    AC.LevelStorage.ReturnCurrentLevelData () (at Assets/AdventureCreator/Scripts/Save system/LevelStorage.cs:167)
    AC.SaveSystem.InitAfterLoad () (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:667)
    AC.SaveSystem.ReceiveDataToLoad (AC.SaveFile saveFile, System.String saveFileContents) (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:575)
    AC.SaveSystem.LoadSaveGame (AC.SaveFile saveFile) (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:409)
    AC.SaveSystem.LoadGame (System.Int32 elementSlot, System.Int32 saveID, System.Boolean useSaveID) (at Assets/AdventureCreator/Scripts/Save system/SaveSystem.cs:325)
    AC.MenuSavesList.ProcessClick (AC.Menu _menu, System.Int32 _slot, AC.MouseState _mouseState) (at Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuSavesList.cs:803)
    AC.PlayerMenus.CheckClick (AC.Menu _menu, AC.MenuElement _element, System.Int32 _slot, AC.MouseState _mouseState) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2352)
    AC.PlayerMenus.CheckClicks (AC.Menu menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:1941)
    AC.PlayerMenus.CheckForInput (AC.Menu menu) (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2060)
    AC.PlayerMenus.CheckForInput () (at Assets/AdventureCreator/Scripts/Controls/PlayerMenus.cs:2048)
    AC.StateHandler.Update () (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:203)

    and I've realized that player custom script itself do not save the standard animation. After loading it switches from 'Idle_setzen' back to 'Idle'

    If I'm trying this script on a sprite animation obect in the hierarchy without anything, the 'animation name' in the inspector of the 'Skeleton Spine' script switch from 'Idle_sitzen' back to 'Idle' too

  • I have updated the script above to fix the error message.

    Try this on a Skeleton Animation component that isn't part of a Character first, i.e. the one you're controlling with the Object: Animate Action.

  • edited June 2022

    sry for the late answer: It works on a Skelleton Anmation component that isnt't part of a Character! Awesome!! but it still don't work on a Character but I think you are aware of it. Thank you very much for this script

  • To have the Spine integration save changes to a "Standard" character animation, an update to both AC and the Spine integration script will be necessary. I will make these changes as part of the next update.

  • That's exactly what I thought your thought's behind your words would be :smiley:
    ...whut? that sounds awesome!! :smiley: thank you very much from the heart! <3 I owe you something for all of your help!

  • It may be that an AC update isn't necessary after all - I've updated the wiki scripts, give them a try.

  • Awesome!!! It works!!! :smiley: :smiley: :smiley:
    I could kiss you! xD
    Thank you! Thank you very much from the heart! I've never find any better support than here! Thank you from a stranger to a stranger helping someone you don't know without expecting something in return just because of a good heart. thank you for your true goodhearted humanity. And for that you deserve highly recognition

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.