Skip to content

Instantly share code, notes, and snippets.

@jamonholmgren
Last active July 29, 2024 02:18
Show Gist options
  • Save jamonholmgren/e4b137e8cf7fd97daaf48ac74112c42e to your computer and use it in GitHub Desktop.
Save jamonholmgren/e4b137e8cf7fd97daaf48ac74112c42e to your computer and use it in GitHub Desktop.
This is a script in GDScript (Godot 4.2) that allows you to set a Node3D as the parent of several GPUParticles3D effects which are all one-shot effects. When you call `trigger()` on it, it'll start them all. When they are all finished, it kills the node. Remember to add all your effects as children to this node.
class_name SingleEffect extends Node3D
var effects: Array[GPUParticles3D] = []
var effects_completed: int = 0
func _ready():
# get all the GPUParticles3D nodes under this node
for child in get_children():
if child is GPUParticles3D: effects.append(child)
func trigger():
for effect in effects:
effect.one_shot = true
effect.emitting = true
effect.finished.connect(_on_effect_finished)
func _on_effect_finished():
effects_completed += 1
if effects_completed == effects.size():
queue_free()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment