• RuntimesUnity
  • Skeleton Graphic and events

  • تم التحرير

Hi all
Is it possible to call events via methods with Skeleton Graphic?

I tried subscribing to events, but they don't seem to 100% of the time get called.

I can see the spine event in the preview

I have the method and script attached to the game object with the skeleton graphic, but at runtime I don't see the print message.

Can someone share some tips? Is it possible? 🙂
Thanks!

    Related Discussions
    ...

    Yes, it is possible to call events via methods with the SkeletonGraphic component in Spine. Here are some steps and tips to ensure that your events are correctly set up and triggered:

    1. Ensure Events are Set in Spine Editor: Make sure that the events are properly set up in the Spine Editor. You can refer to the Spine Events User Guide for more details on how to set up events.

    2. Subscribe to Events in Unity: You need to subscribe to the events in your Unity script. Here is an example of how you can do this:

          using Spine.Unity;
          using UnityEngine;
      
          public class SpineEventHandler : MonoBehaviour {
              public SkeletonGraphic skeletonGraphic;
      
              void Start() {
                  if (skeletonGraphic == null) {
                      skeletonGraphic = GetComponent<SkeletonGraphic>();
                  }
                  skeletonGraphic.AnimationState.Event += HandleEvent;
              }
      
              void HandleEvent(Spine.TrackEntry trackEntry, Spine.Event e) {
                  Debug.Log("Event fired: " + e.Data.Name);
                  // Add your event handling logic here
              }
          }
    3. Check Canvas Renderer Settings: Ensure that the Cull Transparent Mesh parameter of the Canvas Renderer component is disabled. This can affect the rendering of the skeleton and potentially the triggering of events.

    4. Enable Multiple Canvas Renderers: If you are using multiple blend modes, make sure to enable Multiple CanvasRenderers in the SkeletonGraphic component's Advanced settings. This can be done in the Inspector.

    5. Verify Unity and Spine-Unity Versions: Ensure that you are using compatible versions of Unity and the spine-unity runtime. Sometimes issues can arise from version mismatches.

    6. Check for Console Messages: Look for any messages or warnings in the Unity Console that might indicate issues with your setup.

    Here is a link to the spine-unity Runtime Documentation: SkeletonGraphic Component for further reference.

    If you follow these steps and still encounter issues, please provide more details about your setup and any error messages you see.

    IndieDoroid I tried subscribing to events, but they don't seem to 100% of the time get called.
    IndieDoroid

    AnimationState events of SkeletonAnimation and SkeletonGraphic are not called by reflection, your method will reliably be called 0% of the time 😉.
    Item number 2. of Spinebot above shows the proper way, also see this section here:
    https://esotericsoftware.com/spine-unity-main-components#Processing-AnimationState-Events
    Also check out the example scene Spine Examples/Getting Started/2 Controlling Animation.

    Only when using SkeletonMecanim the Spine events will be triggered through the Mecanim animation system and thus trigger named methods, as documented here:
    https://esotericsoftware.com/spine-unity-main-components#SkeletonMecanim-Events

      Harald AnimationState events of SkeletonAnimation and SkeletonGraphic are not called by reflection, your method will reliably be called 0% of the time 😉.

      Got it. Thanks for the confirmation!

      I'll review my code again to see whats going on with my animation state events.
      Thanks🙂