Start animation with no delay

Hello!

I encountered an issue that I am not sure how to solve or how to search for it.

Right now I have set up an object with a sprite called ‘Destructive Obstacle’. It has 2 children: anim, holding the animation, and Trigger_PlayerClose holding the BoxColliderr 2D for the trigger (see the picture).

When the player gets close, the trigger… well… triggers and the animation is played. Initially I used this code:

    private void OnTriggerEnter2D(Collider2D collision)
    {
        initialSprite.a = 0f;
        parent.GetComponent<SpriteRenderer>().color = initialSprite;
        animcontrollerDestuctiveObstacle.SetBool("playerEntered", true);
}

But… using this leads to the alpha of the sprite set to zero (so fine so good) but then the animation doesn’t start immediately. There is a break of about 10 frames where nothing is visible.

I thought about incorporating fixedupdate or update into this.

    private void FixedUpdate()
    {
        if(playAnimation == true)
        {
            animcontrollerDestuctiveObstacle.SetBool("playerEntered", true);
        }

    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        initialSprite.a = 0f;
        parent.GetComponent<SpriteRenderer>().color = initialSprite;
        playAnimation = true;
    }

… but as thought this does not solve the problem. Since I can’t see the reason for this behaviour I am kinda lost. For every hint I’d be grateful.

Thanks,

Andreas

8124707--1053422--Screenshot 2022-05-13 114339.png

I had times set under Settings of the animation. Now I deacitvated exit time and everything works flawlessly. Of course you find that immediately after posting

1 Like