Godot AnimationPlayer: Here's a Problem I Faced and How I Fixed It

It's been a while since I began working on a Vampire Survivors clone using the Godot Engine to learn both game development and the engine itself. I decided to take a short break from game development to focus entirely on learning full-stack web development, planning to return to game development later. However, I thought I should write about this error I encountered to refresh my game development knowledge and help my future self catch up with what I've learned.


The Error

I encountered the error shown in the screenshot below while I was adding a walk animation to the enemy sprite in the game.

I kept encountering this error while trying to play the enemy's walk animation using an AnimationPlayer node. I couldn't figure out what the problem was.


Debugging Process

First, it was clear that the path to the node was incorrect.

Next, I realized the problem was due to having two enemy.tscn files, one inside the Enemy folder and another outside it. I accidentally created two enemy.tscn files at the beginning of this project and was using the AnimationPlayer with the wrong one, which caused the issue.

I couldn't remove the enemy.tscn file outside the Enemy folder, and I couldn't figure out why it kept reappearing.

I tried deleting it and then dragging and dropping the one from the Enemy folder onto the World 2D window (where the sprites are shown) to link the sprite to the .tscn file inside the Enemy folder, not the one I deleted. Despite my efforts to delete it, every time I saved the enemy scene, it would return.


The Fix

The problem was definitely caused by having two enemy.tscn files. Here's what I did to solve it:

  • I deleted the unwanted enemy.tscn file from the root directory.

  • Then, I double-clicked the correct file inside the Enemy folder to ensure I was editing the right scene.

  • I added the AnimationPlayer node and created the walk animation.

  • Finally, I closed the script tab of the old file so it wouldn't reappear.

This fixed the issue, and the animation played correctly.


What I Learned From This

This experience taught me key lessons about working with Godot and game development:

  1. Keep scenes organized
    Duplicate scene files can cause confusion. Maintain a clean folder structure from the start.

  2. Check node paths and references
    Ensure nodes reference the correct scene or path to avoid breaking logic and animations.

  3. Godot doesn’t auto-update references
    Deleting a .tscn file doesn't remove all its references. Make sure to replace it properly.

  4. Understand the editor
    Pay attention to which scene version you're editing. If issues arise, check open tabs and ensure you're on the correct scene file.

  5. Take notes on bugs/fixes when learning
    Writing this down helped reinforce what I learned and also provides future-me with a reference in case I forget. Game development is full of little "gotchas" like this, so keeping track of them helps reduce friction when returning after a break.


Conclusion

Small errors like this might seem minor, but they can waste a lot of time if not caught early. This experience reminded me why version control and file organization are important, even for hobby projects.

I'm glad I took the time to solve this issue, and it feels good to be back in game development mode, even if it's just to reflect on a past problem.

I hope this post helps someone avoid the same mistake. Thanks for reading :)


1
Subscribe to my newsletter

Read articles from Saptaparno Chakraborty directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Saptaparno Chakraborty
Saptaparno Chakraborty

I'm a budding software engineer and a hobbyist game developer. I enjoy building things.