Problem with instancing multiple enemies in a scene, animationplayers won't work properly

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

I’m not sure if this is a bug, but I’ll ask for a solution here.
I have a slime scene that attacks the player. It uses an AnimationPlayer node which contains the attack animations. The animations have tracks for AnimatedSprite:animation, AnimatedSprite:frames, and a track for disabling and enabling an Area2D’s collision shapes, which are its attack areas.

The only problem comes when instancing multiple of them. When I instance multiple slimes, I get an error where the track couldn’t resolve, and the AnimatedSprite and Area2D nodes weren’t found.

Then they won’t do their attack animation, or their animations glitch weirdly.
When I tried to restart the editor, the AnimationPlayer’s animations were cleared of their tracks. I’ve had this problem for a while now, and I’ve tried saving the animations, deleting the slime instances, but the bug always happens no matter what. I want to know how to fix it.

:bust_in_silhouette: Reply From: Jorge

Hi, just need to get the correct path, just just get_node() instead of $ and insert the correct path , you could drag it form the editor.
good luck

:bust_in_silhouette: Reply From: owlisGODOT

Luckily, I’ve found the solution to this problem!
Turns out I had to put each of them under their own respective node. That way, their animations can work more efficiently.
I realized that each node must control their own things, and that was the reason why their animations were glitching.

I’m having the same problem and I’m really confused because I didn’t have this problem with a previous project that used the same code.

When you say “put each of them under their own respective node”: What’s them? The enemies? The animations? The tracks?

Marilius | 2023-06-09 01:01

Nevermind, I figured out my problem. It was actually because the node and animationplayer were created in the editor and the animations made when they were part of a larger scene.

Then I saved branch as scene. Which screwed up the animationplayers root node. Once I changed the root node to the new scene’s root node and rebuilt the animations, everything worked fine with multiple instances.

Marilius | 2023-06-09 01:22