← Pixel Dreamer Studio

GPUParticles2D trails not working

In Compatibility, trails hide the particles. Turn a streak along the velocity instead.

The Compatibility renderer, which web exports use, does not draw particle trails. With trail_enabled on, our GPUParticles2D drew nothing at all, not even the particle, and Godot only printed a warning. Leave trails off and use a long, thin texture with particle_flag_align_y on in the ParticleProcessMaterial: each particle turns so it points where it flies.

Two sprays of thin orange streaks. On the left every streak stands straight up. On the right each streak points the way it is flying
The script below in Godot 4.7 with the Compatibility renderer. Left: Align Y off. Right: the script as written.

The code

Attach this to a GPUParticles2D for sparks that burst up and fall. The script draws the streak texture itself, 4 by 24 pixels, so it runs as it is. The align line is the fix. The leading end is the bottom of the texture, so make that end bright.

extends GPUParticles2D
## 2D sparks drawn as short streaks that point where they fly. Works in the
## Compatibility renderer that web exports use, where 2D particle trails are not drawn.


func _ready() -> void:
	amount = 40
	lifetime = 0.8
	texture = make_streak()
	var m := ParticleProcessMaterial.new()
	m.particle_flag_align_y = true  # the fix: turn each spark so its long side follows its velocity
	m.direction = Vector3(0, -1, 0)
	m.spread = 60.0
	m.initial_velocity_min = 250.0
	m.initial_velocity_max = 400.0
	m.gravity = Vector3(0, 600, 0)
	process_material = m
	# trail_enabled = true would hide every particle in the Compatibility renderer


func make_streak() -> Texture2D:
	# 4 px wide and 24 px long: clear at the top, bright at the bottom.
	# The bottom of the texture is the side that leads.
	var img := Image.create(4, 24, false, Image.FORMAT_RGBA8)
	for y in 24:
		var a := float(y + 1) / 24.0
		for x in 4:
			img.set_pixel(x, y, Color(1.0, 0.8, 0.4, a))
	return ImageTexture.create_from_image(img)

What we measured

One spark flying right at 400 pixels per second with no gravity. We measured the box around its lit pixels and how bright each end was (red + green + blue, 0 to 3). Two runs gave the same picture.

What to change

The same thing for 3D particles: particle trails in Compatibility. Other features a web export skips: particles not working in a web export. 2D sparks that land on a floor: GPUParticles2D collision.

Tested in Godot 4.7 with the Compatibility renderer.

More how-tos: When particles do not show up