3D Dash Ghost Fading Effect Issue

Godot Version

4.1.1

Question

Hello community! So, I am working on making a dash mechanic in 3d. Essentially what happens is I spawn a “ghost”, which is a meshinstance3d that is a copy of my character. The ghost code is set up such that, when it spawns, it just tweens the alpha of the albedo color of the material to zero, like so

func _ready():
	ghost()

func ghost():
	# Ghosting body, left eye, and right eye
	var tweenFadeBody = create_tween()
	tweenFadeBody.tween_property(self.mesh.material, "albedo_color:a", 0, Global.PLAYER_GHOST_FADE_LENGTH)
	var tweenFadeEyeLeft = create_tween()
	tweenFadeEyeLeft.tween_property(eyeLeft.mesh.material, "albedo_color:a", 0, Global.PLAYER_GHOST_FADE_LENGTH)
	var tweenFadeEyeRight = create_tween()
	tweenFadeEyeRight.tween_property(eyeRight.mesh.material, "albedo_color:a", 0, Global.PLAYER_GHOST_FADE_LENGTH)

	# When the tweens are done, remove this and all the sub-meshes
	await tweenFadeBody.finished
	queue_free()

In my player script, every few milliseconds, when I dash, it spawns a ghost like so

func spawnGhost():
	var ghost = load(ghostScene).instantiate()
	var uniqueMaterial = ghost.mesh.material.duplicate()
	ghost.mesh.material = uniqueMaterial
	ghost.position = position
	ghost.rotation = bodyMesh.rotation
	get_tree().root.add_child(ghost)
	ghostsSpawnedThisDash += 1

There are two issues. I believe they are related.

  1. All of the spawned ghosts fade at the same time. As in, they all fade out on the same frame. I thought this was an issue with the material being the same, so that is why I duplicate the material here.
  2. if I load the ghostScene at the top of the script (just once and not each run), it will only produce the set of ghosts one time. Aka when I try to dash a second time it doesn’t spawn ghosts (or, perhaps, it spawns them with alpha of zero)

THANK YOU so much in advance :heart: