- Home /
Animation appearing in scene but not in game
I have this animation I've created for when the player's y position goes below a certain value. It displays the word 'Dead' on the screen which increases in size. When testing this it works perfectly in the scene, but won't appear in the game view? The attached screenshot shows how the animation appears (and works at the correct time) in the scene view, but not in the game view. Could anyone help as to why this would be?
Answer by Cuttlas-U · Sep 09, 2017 at 01:28 PM
hi; i think the reason that u can see it in editor and not in game window is the Z position of the sprite ;
try to change the Z value of transform position ;
You are my hero today!!!! I had a SMH moment...I learned why you should zero X/Y/Z when making a new object. thank you Sir!
Answer by StevenUnu · Sep 09, 2017 at 01:37 PM
It may be that your "Dead" Sprite is in behind the camera so it won't be rendered. Click that little button in the editor above the scene view which says "2d" and you will see your scene in 3d. This way you could set the Z axis properly.
Answer by Peakz · Sep 09, 2017 at 03:51 PM
@Cuttlas-U @StevenUnu Thank you both for your replies, I had already tried adjusting the Z position of the sprite so unfortunately that is not the fix. Maybe it's something to do with my code:
public Transform playerPos;
SpriteRenderer sr;
Animator anim;
// Use this for initialization
void Start ()
{
anim = GetComponent<Animator>();
sr = GetComponent<SpriteRenderer>();
}
// Update is called once per frame
void Update ()
{
if (playerPos.position.y <= -9)
{
sr.enabled = true;
anim.SetBool("isDead", true);
}
}
I have already tried order in layer but thanks for the suggestion!
When you are in scene view, you see the sprite as the image you assigned to the Image component. As well as I understood, your sprite has an animation. Is your default state in the animator state machine a visible image? If not, you should make sure your transition conditions DO really somewhen succeed. If it is a visible image or animation, then you should make sure that no transition to a non-visible image is made. If this doesn't help, try using SetActive(bool active) ins$$anonymous$$d of enabled (I did not test it so I'm not sure it works)
I tried rerecording the Idle animation with the sprite renderer turned on (it is turned off unless player pos.y < -9), which seems to make the animation now appear in game. However I now have a new issue of the animation plays once then disappears. I need this animation to stay in it's final frame ins$$anonymous$$d of disappearing, like a classic 'you are dead' screen. Any idea as to why it's disappearing?
Try setting "Has exit time " and "Fixed duration" off in the transition to the Dead State. I'm not sure if this will have any effect or rather any good effect but it's worth trying.
Answer by Peakz · Sep 09, 2017 at 06:48 PM
I literally just found the fix, I tried ticking 'Apply Root Motion' on the animation component and that seems to have fixed it. No idea why at all but it seems to work. Thanks for all your suggestions!