Godot Version
v4.6.3.stable.official [7d41c59c4]
Question
I am trying to creating a particle system for a 2d platform fighter which I am making In Godot. I am running into a bug which I have spent the last week attempting to fix, and I have narrowed it down to being an issue with how the AnimationPlayer is affecting the objects in the original when an animation is played on a duplicated child of it.
This is the code which is supposed to enable and play the animation on a version of the particle in the scene when ever the player jumps, but if the particle is already in use and on screen will make a temporary copy and then play the animation which enables the particles on that.
I need help in both knowing if the problem is actually what I diagnosed it as and if so then what do I need to do to make the animation tracks on the duplicate to affect the objects on the duplicate
extends Node
@export var LANDING_PARTICLES : PackedScene
func activateParticle(particleName: String, position: Vector2):
var particleParent = find_child(particleName)
var particleAnimator:AnimationPlayer = particleParent.find_child("AnimationPlayer")
if particleAnimator.is_playing():
var copy:Node2D = LANDING_PARTICLES.instantiate().duplicate()
add_child(copy)
copy.position = position
copy.find_child("AnimationPlayer").play(particleName)
else:
particleParent.position = position
particleAnimator.play(particleName)
func _process(delta: float) -> void:
copyKiller()
func copyKiller():
for i in get_children():
if(i.get_meta("Clone") && !i.find_child("AnimationPlayer").is_playing()):
i.queue_free()