Animation called on duplicates animation player effecting the original object

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()

Just do a deep duplicate.

How do I do a deep Duplicate using the duplicate method that is part of the Node class

Use DuplicateFlags mentioned in the function defintion: Node — Godot Engine (stable) documentation in English

I’d recommend just starting with DUPLICATE_INTERNAL_STATE and see if that solves your problem.

enum DuplicateFlags:

● DUPLICATE_SIGNALS = 1
Duplicate the node's signal connections that are connected with the Object.CONNECT_PERSIST flag.
● DUPLICATE_GROUPS = 2
Duplicate the node's groups.
● DUPLICATE_SCRIPTS = 4
Duplicate the node's script (also overriding the duplicated children's scripts, if combined with DUPLICATE_USE_INSTANTIATION).
● DUPLICATE_USE_INSTANTIATION = 8
Duplicate using PackedScene.instantiate(). If the node comes from a scene saved on disk, reuses PackedScene.instantiate() as the base for the duplicated node and its children.
● DUPLICATE_INTERNAL_STATE = 16
Duplicate also non-serializable variables (i.e. without @GlobalScope.PROPERTY_USAGE_STORAGE).

● DUPLICATE_DEFAULT = 15
Duplicate using default flags. This constant is useful to add or remove a single flag.
# Duplicate non-exported variables.
var dupe = duplicate(DUPLICATE_DEFAULT | DUPLICATE_INTERNAL_STATE)