【Help】animation player doesn't display sprite when instantiated

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By amaou310

I am very new to godot and game engine or programming. I would appreciate if someone could teach me how to display sprite on the screen.

I made player animation using Animation Player inside a scene called PlayerAniamtion. And I instantiated that scene as a child of KinematicBody2D inside another scene. However, the sprite does not show up.

:bust_in_silhouette: Reply From: Gluon

It looks from the error as though you havent actually added a sprite to the animation player.

The documentation is here

You will see in the editor there is a section called frames, you have to add the sprites there. Hope this helps.

Thank you for the comment, but sprites are already in frames.
I reuploaded the gif so please check

amaou310 | 2022-04-08 10:39

Oh okay so I think I can see what is going wrong here. You need to create the whole player as a single scene not add a node2d with a bunch of animations hanging off of it.

Nice looking animations by the way, they look nice.

What you want to do is create a scene (call it player or something) but the top node should be a kinematic body 2d. The under that have a collision shape and an animation player. When you instantiate a player you call the whole set of nodes then with the appropriate scripts.

You should only need one animation player node, within that node you can add all of the animations and name them accordingly. To be honest it is the structure of the nodes which is causing you a problem here.

The documentation i linked before outlines this so if you create a test project and just follow the documentation that should show you how to do it in your main project.

Gluon | 2022-04-08 11:05

It worked!! I made new scene where have kinematicbody2d only. and I just instantiated animation-scene, and i can see the sprite! Thank You so much.

But, i still do not understand why the sprite didnt show up when kinematicbody2d was under 2d node.

amaou310 | 2022-04-08 12:24

Yeah node structure is important not only for being able to call the right functions in scenes lower in the scene tree but also because some nodes dont have certain functions that other nodes have.

The documentation explains it all here

Nodes and Scenes — Godot Engine (latest) documentation in English

hopefully that will help, getting the node structure correct is very important in godot.

Gluon | 2022-04-09 16:32