- Home /
The logic works but the main issue was mostly with the use of layers in animator that causes the undesirable effects stated in this problem
Can't modify the property changed by 2D animation via LateUpdate() in 1 frame
I have been digging around regarding this and all that I saw was turning off the Write Defaults and changed the modified property in LateUpdate. But apparently both seems not to work if I want to execute the property changes programmaticaly in 1 frame.
My scenario here is I want my 2D character to have an invincible mode where the player is fading in and out while still able to play the running, walking, jumping and other related animations. I also have a grow and shrink animation that also has the fading effect. So I don't want the fading effect to disappear when the player is not invincible.
So I made the invincible mode animation by sliding up and down the alpha of the sprite's color via animation recording mode. Then I made script that will only play that animation when the player is invincible and after some duration, the invincibility wears off. here is the snippet of it:
void FixedUpdate()
{
if (_isInvincible)
{
if (_invincibleTimer <= _maxInvincibilityTime)
{
_invincibleTimer += Time.deltaTime;
_animationPlayer.PlayInvincibleModeAnimation(true);
}
else
{
_animationPlayer.PlayInvincibleModeAnimation(false);
_isInvincible = false;
_invincibleTimer = 0f;
}
}
}
so as per that logic, I forced the sprite to return the alpha to 1 once _isInvincible is false in LateUpdate(). But alas, this logic affected my growth and shrink animations. Here's the code for that:
void LateUpdate()
{
if (!_isInvincible)
{
this._spriteRenderer.color = new Color(_spriteRenderer.color.r, _spriteRenderer.color.g, _spriteRenderer.color.b, 1f);
}
}
I modified that code to only run once in 1 frame and my growth and shrink animation was back to normal but the invincible animation is affected where the player became slightly transparent after the invincibility wears off. (the alpha value is retained on which the frame of the animation is stopped to transition to another animation).
Follow this Question
Related Questions
How to manage 2D sprite animations correctly? 0 Answers
Animation stuck on first image 0 Answers
Animator Condition Not Working 0 Answers
Shooter 2D: Character animation only runs once 1 Answer
Get Pos X and Pos Y of current playing Blend Tree motion 0 Answers