• RuntimesUnreal
  • Spine Animation for Timer

For some reason, I hope to use Spine animation itself to implement some timed events
I know Spine comes with a great event mechanism that allows me to add events to animations
But when I encounter the following requirements, the event doesn't seem so useful
I have many characters, each with an attack animation and a still animation
I hope there is an event where the attack animation is triggered after playing for 1 second
But this attack animation may have a duration of less than 1 second, or it may have a duration greater than 1 second
For characters whose attack animation itself is less than 1 second, does this feature seem impossible to achieve with events?
Then I thought of adding empty animation to a TrackIndex without any animation and listening for its trigger
However, this does not work
Perhaps because I am a beginner, I have not learned certain functions
Can someone kind tell me how to solve this problem?

    Related Discussions
    ...

    youling In that case, I think it would be better to use the Timer provided by UE than to use the API provided by spine-ue. I guess Set Timer by Function Name or Set Timer by Event would be appropriate. There is an official tutorial on how to use Timers, so you may want to refer to that:
    https://dev.epicgames.com/documentation/en-us/unreal-engine/using-timers-in-unreal-engine

      Misaki I know that Unreal Timer can easily accomplish tasks that require a specified operation to be executed after 1 second. However, the situation I am currently facing is that my character may be set to Custom Time Dilation at any time, but the timer will not be affected by Custom Time Dilation because it is timed in the global Tick. When I expect to execute the operation after 1 second, my character may have been set to Custom Time Dilation 2.0 at 0.5 seconds, which means that I only need to wait another 0.25 seconds to trigger my specified task. But because my attack animation may not be longer than 1 second, it may trigger my task after the current animation is played, so I cannot directly add events to the animation to solve the problem. Although I know I can add a floating-point number to each timed task and time it in the current character's Tick, when there are too many timed tasks, I am forced to add many variables and their triggering conditions. I'm just thinking about using Spine's tick and an empty TrackIndex to mark the time point I want and trigger the callback function I specified. Perhaps it's also because I don't know much about Unreal. Is there any other way to implement a Delay affected by Customs Time Dilation?

        youling Thank you for clarifying your situation. I think you may want to create a custom timer system in C++ that respects your character's Custom Time Dilation. I'm not a C++ expert, but the code suggested by chatGPT seems to write the following:

        void AYourCharacter::StartAttackWithCustomTimer()
        {
            // Start the attack animation
            PlayAttackAnimation();
        
            // Calculate adjusted delay time based on Custom Time Dilation
            float CustomTimeDilation = GetWorld()->GetWorldSettings()->TimeDilation * CustomTimeDilationValue;
            float AdjustedTime = 1.0f / CustomTimeDilation;
        
            // Set a custom timer
            GetWorld()->GetTimerManager().SetTimer(
                CustomTimerHandle,
                this,
                &AYourCharacter::OnCustomTimerElapsed,
                AdjustedTime,
                false
            );
        }
        
        void AYourCharacter::OnCustomTimerElapsed()
        {
            // Execute the task
            TriggerNextAction();
        }

        Although I am not sure if it will work perfectly in your case, I hope it will be of some help.

          Misaki
          Thank you for your reply. Although the code provided by GPT cannot solve the problem, I have implemented a simplified version of a local timer mounted on the actor in a similar way to respond to custom time dilation.