← Pixel Dreamer Studio

Changing one particle effect's color changes all of them

Copies of a scene share its materials. Give each copy its own.

A material set in the Inspector is saved once in the scene, and every copy you place or instantiate() uses that same material. Change color on one copy's process_material and every copy changes. Give each copy its own: process_material = process_material.duplicate() in _ready(), or tick Local to Scene on the material in the Inspector.

Two groups of three small particle fountains. In the left group all three are blue. In the right group they are red, green and blue
The script below in Godot 4.7 with the Compatibility renderer. Three copies of one scene on each side, set to red, green and blue in that order. Left: the material as it is in the scene. Right: with the script.

The code

Attach this to the GPUParticles3D in the scene you place many times, then call set_color() on any copy. The line in _ready() is the fix. The color only shows if the draw material has Vertex Color, Use as Albedo on: particle color not working.

extends GPUParticles3D
## Attach to the GPUParticles3D of a scene you place many times, such as hit sparks,
## to recolor one copy without recoloring the others. A process material set in the
## Inspector is shared by every copy of the scene until each copy makes its own.


func _ready() -> void:
	process_material = process_material.duplicate()  # the fix: this copy gets its own material


func set_color(c: Color) -> void:
	# shows only if the draw material has Vertex Color, Use as Albedo on
	(process_material as ParticleProcessMaterial).color = c

What we measured

We packed one emitter with its materials into a scene, made two copies side by side, changed the color of the left one to red (1.00/0.20/0.10) and read the color of both. Two runs gave the same result.

Script or Local to Scene

Both gave each copy its own material in our test. Local to Scene is a checkbox and no code, but it is easy to miss when you make a new material. The script keeps working whatever material you put in the scene.

What to change

Effects at the point of a hit: spawn a hit effect at the impact point. Many hits at once: hit sparks from an emitter pool.

Tested in Godot 4.7 with the Compatibility renderer.

More how-tos: Play, stop and remove effects