Thank you, this helped a lot
I separated the recoil animation in 2 parts, one for the arm's recoil animation, and other for the back, on track 5, i did that because the back's recoil animation while running was strange, and now it's working very nicely
but now i'm getting this error message:
SerializedObjectNotCreatableException: Object at index 0 is null
UnityEditor.Editor.CreateSerializedObject () (at <00d63564201b48698d51680c10078897>:0)
UnityEditor.Editor.GetSerializedObjectInternal () (at <00d63564201b48698d51680c10078897>:0)
UnityEditor.Editor.get_serializedObject () (at <00d63564201b48698d51680c10078897>:0)
Spine.Unity.Editor.SpineAtlasAssetInspector.OnEnable () (at ./Library/PackageCache/com.esotericsoftware.spine.spine-unity@7883f0fafd/Editor/spine-unity/Editor/Asset Types/SpineAtlasAssetInspector.cs:71)
this is the new code:
public class SpineWeaponSelector : MonoBehaviour
{
[SerializeField] private SkeletonAnimation skeletonAnim;
[SerializeField] private AnimationReferenceAsset weapon1;
[HideInInspector] public AnimationReferenceAsset currentWeapon;
[SerializeField] private AnimationReferenceAsset animationWithNoBackRecoil;
[HideInInspector] public int currentWeaponHand;
private TrackEntry trackEntry4, trackEntry5;
void Start()
{
currentWeapon = weapon1;
UpdateWeapon(1);
}
private void Update()
{
}
public void UpdateWeapon(int weaponHand)
{
skeletonAnim.state.SetAnimation(1, currentWeapon, true);
currentWeaponHand = weaponHand;
}
public void Recoil()
{
trackEntry4 = skeletonAnim.state.SetAnimation(4, currentWeapon.name + "_recoil", false);
//trackEntry5.MixBlend = MixBlend.Add;
skeletonAnim.state.AddEmptyAnimation(4, 0.2f, 0);
if(skeletonAnim.state.GetCurrent(0).Animation != animationWithNoBackRecoil.Animation)
{
trackEntry5 = skeletonAnim.state.SetAnimation(5, currentWeapon.name + "_recoil_back", false);
skeletonAnim.state.AddEmptyAnimation(5, 0.2f, 0.1f);
}
}
}