SequencerCommand DoTween

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Haluk
Posts: 5
Joined: Mon Jul 08, 2024 11:32 am

SequencerCommand DoTween

Post by Haluk »

Hi.
I try to code a sequencer command which includes dotween to make some little animations during conversation. But if i skip quickly all of them the Recttransforms can not go back to their initial positions on destroy moment even if i state them what init positions thry have. But if i add some delay then they work on sequencer field when i type required somemethodbytween@0.1. Which stuff leads such problem? ^^ :roll: :roll:
User avatar
Tony Li
Posts: 22092
Joined: Thu Jul 18, 2013 1:27 pm

Re: SequencerCommand DoTween

Post by Tony Li »

Hi,

Can you share your DOTween sequencer command? (If you can't show it publicly, you can email a copy to tony (at) pixelcrushers.com.)

If the command must run even if the player skips ahead, put 'required' in front of it. For example, to guarantee that the second command runs below, I used 'required':

Code: Select all

AnimatorPlay(Talk);
required AnimatorPlay(Idle)@Message(Typed)
If your command is running and is interrupted, but you need to make sure it ends up in a specific position, make sure the command has an OnDestroy() method. You can add a Debug.Log() call in OnDestroy() to confirm that it's being run.
Haluk
Posts: 5
Joined: Mon Jul 08, 2024 11:32 am

Re: SequencerCommand DoTween

Post by Haluk »

Yes ofcourse my code sippet is below. I tried several code snippets and at least last one i used here. ^^

Code: Select all

public class SequencerCommandScaleSequenceRect : SequencerCommand
{

    Sequence m_Seq;

    RectTransform m_Rect;

    Vector3 m_InitScale;

    float m_Xval;

    public void Awake()
    {
        m_Xval = GetParameterAsFloat(0, 0);

        float m_Duration = GetParameterAsFloat(1, 1);

        string m_ObjectName = GetParameter(2, string.Empty);

        GameObject m_GameObject = GameObject.Find(m_ObjectName);

        if (m_GameObject != null)
        {
            m_Rect = m_GameObject.GetComponent<RectTransform>();

            m_InitScale = m_Rect.localScale;

            if (m_Rect != null) {
                ScaleRectTransformWihSequenceTween(m_Rect, m_Xval, m_InitScale, m_Duration);
            }
            else {
                Debug.LogWarning($"SequencerCommandMoveObjectWithDOTween: {m_ObjectName} named GO has not Recttransform component!");
            }
          
        }
        else
        {
            Debug.LogWarning($"SequencerCommandMoveObjectWithDOTween: {m_ObjectName} named GO not found.");
            Stop();
        }
    }

    Tween m_ScaleTween0;
    Tween m_ScaleTween1;

    private Sequence ScaleRectTransformWihSequenceTween(RectTransform mrect, float scaler, Vector3 initScaler, float duration)
    {

        m_Seq = DOTween.Sequence();

        m_ScaleTween0 = mrect.DOScale(scaler, duration)
            .SetEase(Ease.InOutCubic)
            .SetUpdate(true);

        m_ScaleTween1 = mrect.DOScale(initScaler, duration)
            .SetEase(Ease.InOutCubic)
            .SetUpdate(true);

        m_Seq.Append(m_ScaleTween0)
            .Append(m_ScaleTween1)
            .SetUpdate(true)
            .OnComplete(OnSeqenceDestroy)
            .OnKill(OnSeqenceDestroy);

            return m_Seq;
    }

    public void OnSeqenceDestroy() {
        m_Rect.localScale = m_InitScale;
        Debug.LogWarning($"Scale Backed Up > Init > {m_InitScale}, Rect: {m_Rect.localScale}.");
        Stop();
    }

    public void OnDestroy() {

        if (m_Seq != null) {
            m_Seq.Kill();
            //int numberOfKilledTween = DOTween.Kill(m_Seq);
            //int numberOfKilledTween = DOTween.KillAll();
            //Debug.LogWarning($"Number Of Killed Tween > {numberOfKilledTween}.");
        }

        m_Rect.localScale = m_InitScale;
    }
}
In addition, i used the "required ScaleSequenceRect(1.1, 0.15, ActorPortrait)@0.05;" for successive sequencers. Then works properly. But if i don't add wait time and if i click on the continue button very quickly it missing backing up with init values.
Last edited by Haluk on Mon Jul 29, 2024 4:22 pm, edited 1 time in total.
User avatar
Tony Li
Posts: 22092
Joined: Thu Jul 18, 2013 1:27 pm

Re: SequencerCommand DoTween

Post by Tony Li »

That looks okay. Are you saying that OnDestroy() does not run if the player skips ahead before the DOTween sequence has finished?

Are there any errors or warnings in the Console window?

If you add a Debug.Log() as the first line in OnDestroy(), does it appear in the Console?
Haluk
Posts: 5
Joined: Mon Jul 08, 2024 11:32 am

Re: SequencerCommand DoTween

Post by Haluk »

i don't see any error during button clicking even if i click on the continue button very quickly. Also each tween period per clicking is running even if it is miss backing up the initial values on destroy. When i use them very quickly then init values are also changing to the new recttransform init values. The Debug method is also working on destroy cycle but init values are not assigning back.
User avatar
Tony Li
Posts: 22092
Joined: Thu Jul 18, 2013 1:27 pm

Re: SequencerCommand DoTween

Post by Tony Li »

Is the Awake() method running? (You can add a Debug.Log() line to confirm.)

If Awake() isn't running, then you could add a bool variable that lets you know whether the init values are valid. Example:

Code: Select all

private bool m_isInitialized = false;

void Awake()
{
    m_isInitialized= true;
    ...
void OnDestroy()
{
    if (!m_isInitialized) return;
    ...
Post Reply