So, I decided to add a dust spawner for my pong game so that plenty of dusts could spawn at once without one suddenly disappearing. But it didn’t work
Basically, the dust spawns but when another one spawns the previous one disappears instead of finishing. I even searched up a topic that told me to go check the remote tab of the scene tree, and somehow the dust was actually spawning, yet I still couldn’t see any signs of those
Here’s the code I’m using for this, any suggestions?
var collider_name: String = collision.get_collider().name
if (collider_name == "Paddle" or collider_name == "Borders"):
Spawn_Dust(collision.get_position())
Can I also ask you about this %Dust unique name?
I believe you would set the properties of your new new_dust but you simply add it to the scene without doing anything with it
IT WORKED!!! So I forgot to change the %Dust to new_dust, and set it’s values after spawning it instead of before it existed. It all makes sense now. Thank you SO much
My question now is, how would I delete the dust particles that have finished their animation? Because now the scene tree is just having more and more cloned dust particles that have already finished, which might cause performance issues.
It worked! Here’s the newly updated code (with comments) for anyone with the same issue:
func Spawn_Dust(collision_point: Vector2) -> void:
var new_dust = preload("res://Scenes/dust.tscn").instantiate() #create dust instance
add_child(new_dust) #add that instance to the scene tree
new_dust.global_position = collision_point #set properties for the instance
new_dust.emitting = true #^^^
new_dust.restart() #^^^
await get_tree().create_timer(2.3).timeout #wait for amount of time in the brackets (one with numbers)
new_dust.queue_free() #after ^^^, remove dust instance to free space
var collider_name: String = collision.get_collider().name #variable to store the name of the colliders
if (collider_name == "Paddle" or collider_name == "Borders"):
Spawn_Dust(collision.get_position()) #spawn that dust instance