GPUParticles2D
Inherits: Entity2D < CanvasItem < Entity < Object
Description
Section titled “Description”A 2D particle emitter.
2D particle node used to create a variety of particle systems and effects. GPUParticles2D features an emitter that generates some number of particles at a given rate.
Use the process_material property to add a ParticleProcessMaterial to configure particle appearance and behavior. Alternatively, you can add a ShaderMaterial which will be applied to all particles.
2D particles can optionally collide with LightOccluder2D, but they don’t collide with PhysicsBody2D nodes.
Properties
Section titled “Properties”| Type | Name | Default |
|---|---|---|
| int | amount |
8 |
| float | amount_ratio |
1.0 |
| float | collision_base_size |
1.0 |
| DrawOrder | draw_order |
1 |
| bool | emitting |
true |
| float | explosiveness |
0.0 |
| int | fixed_fps |
30 |
| bool | fract_delta |
true |
| float | interp_to_end |
0.0 |
| bool | interpolate |
true |
| float | lifetime |
1.0 |
| bool | local_coords |
false |
| bool | one_shot |
false |
| float | preprocess |
0.0 |
| Material | process_material |
|
| float | randomness |
0.0 |
| int | seed |
0 |
| float | speed_scale |
1.0 |
| EntityPath | sub_emitter |
EntityPath("") |
| Texture2D | texture |
|
| bool | trail_enabled |
false |
| float | trail_lifetime |
0.3 |
| int | trail_section_subdivisions |
4 |
| int | trail_sections |
8 |
| bool | use_fixed_seed |
false |
| Rect2 | visibility_rect |
Rect2(-100, -100, 200, 200) |
Methods
Section titled “Methods”| Returns | Method |
|---|---|
| Rect2 | capture_rect() const |
| void | convert_from_particles(particles: Entity) |
| void | emit_particle(xform: Transform2D, velocity: Vector2, color: Color, custom: Color, flags: int) |
| void | request_particles_process(process_time: float, process_time_residual: float = 0) |
| void | restart(keep_seed: bool = false) |
Signals
Section titled “Signals”finished
finished()
Emitted when all active particles have finished processing. To immediately restart the emission cycle, call restart().
This signal is never emitted when one_shot is disabled, as particles will be emitted and processed continuously.
Note: For one_shot emitters, due to the particles being computed on the GPU, there may be a short period after receiving the signal during which setting emitting to true will not restart the emission cycle. This delay is avoided by instead calling restart().
Enumerations
Section titled “Enumerations”DrawOrder
enum DrawOrder
DRAW_ORDER_INDEX = 0
Particles are drawn in the order emitted.
DRAW_ORDER_LIFETIME = 1
Particles are drawn in order of remaining lifetime. In other words, the particle with the highest lifetime is drawn at the front.
DRAW_ORDER_REVERSE_LIFETIME = 2
Particles are drawn in reverse order of remaining lifetime. In other words, the particle with the lowest lifetime is drawn at the front.
EmitFlags
enum EmitFlags
EMIT_FLAG_POSITION = 1
Particle starts at the specified position.
EMIT_FLAG_ROTATION_SCALE = 2
Particle starts with specified rotation and scale.
EMIT_FLAG_VELOCITY = 4
Particle starts with the specified velocity vector, which defines the emission direction and speed.
EMIT_FLAG_COLOR = 8
Particle starts with specified color.
EMIT_FLAG_CUSTOM = 16
Particle starts with specified CUSTOM data.
Property descriptions
Section titled “Property descriptions”amount
int amount = 8
The number of particles to emit in one emission cycle. The effective emission rate is (amount * amount_ratio) / lifetime particles per second. Higher values will increase GPU requirements, even if not all particles are visible at a given time or if amount_ratio is decreased.
Note: Changing this value will cause the particle system to restart. To avoid this, change amount_ratio instead.
amount_ratio
float amount_ratio = 1.0
The ratio of particles that should actually be emitted. If set to a value lower than 1.0, this will set the amount of emitted particles throughout the lifetime to amount * amount_ratio. Unlike changing amount, changing amount_ratio while emitting does not affect already-emitted particles and doesn’t cause the particle system to restart. amount_ratio can be used to create effects that make the number of emitted particles vary over time.
Note: Reducing the amount_ratio has no performance benefit, since resources need to be allocated and processed for the total amount of particles regardless of the amount_ratio. If you don’t intend to change the number of particles emitted while the particles are emitting, make sure amount_ratio is set to 1 and change amount to your liking instead.
collision_base_size
float collision_base_size = 1.0
Multiplier for particle’s collision radius. 1.0 corresponds to the size of the sprite. If particles appear to sink into the ground when colliding, increase this value. If particles appear to float when colliding, decrease this value. Only effective if ParticleProcessMaterial.collision_mode is ParticleProcessMaterial.COLLISION_RIGID or ParticleProcessMaterial.COLLISION_HIDE_ON_CONTACT.
Note: Particles always have a spherical collision shape.
draw_order
DrawOrder draw_order = 1
Particle draw order.
emitting
bool emitting = true
If true, particles are being emitted. emitting can be used to start and stop particles from emitting. However, if one_shot is true setting emitting to true will not restart the emission cycle unless all active particles have finished processing. Use the finished signal to be notified once all active particles finish processing.
Note: For one_shot emitters, due to the particles being computed on the GPU, there may be a short period after receiving the finished signal during which setting this to true will not restart the emission cycle.
Tip: If your one_shot emitter needs to immediately restart emitting particles once finished signal is received, consider calling restart() instead of setting emitting.
explosiveness
float explosiveness = 0.0
How rapidly particles in an emission cycle are emitted. If greater than 0, there will be a gap in emissions before the next cycle begins.
fixed_fps
int fixed_fps = 30
The particle system’s frame rate is fixed to a value. For example, changing the value to 2 will make the particles render at 2 frames per second. Note this does not slow down the simulation of the particle system itself.
fract_delta
bool fract_delta = true
If true, results in fractional delta calculation which has a smoother particles display effect.
interp_to_end
float interp_to_end = 0.0
Causes all the particles in this node to interpolate towards the end of their lifetime.
Note: This only works when used with a ParticleProcessMaterial. It needs to be manually implemented for custom process shaders.
interpolate
bool interpolate = true
Enables particle interpolation, which makes the particle movement smoother when their fixed_fps is lower than the screen refresh rate.
lifetime
float lifetime = 1.0
The amount of time each particle will exist (in seconds). The effective emission rate is (amount * amount_ratio) / lifetime particles per second.
local_coords
bool local_coords = false
If true, particles use the parent node’s coordinate space (known as local coordinates). This will cause particles to move and rotate along the GPUParticles2D node (and its parents) when it is moved or rotated. If false, particles use global coordinates; they will not move or rotate along the GPUParticles2D node (and its parents) when it is moved or rotated.
one_shot
bool one_shot = false
If true, only one emission cycle occurs. If set true during a cycle, emission will stop at the cycle’s end.
preprocess
float preprocess = 0.0
Particle system starts as if it had already run for this many seconds.
Note: This can be very expensive if set to a high number as it requires running the particle shader a number of times equal to the fixed_fps (or 30, if fixed_fps is 0) for every second. In extreme cases it can even lead to a GPU crash due to the volume of work done in a single frame.
process_material
Material process_material
Material for processing particles. Can be a ParticleProcessMaterial or a ShaderMaterial.
randomness
float randomness = 0.0
Emission lifetime randomness ratio.
seed
int seed = 0
Sets the random seed used by the particle system. Only effective if use_fixed_seed is true.
speed_scale
float speed_scale = 1.0
Particle system’s running speed scaling ratio. A value of 0 can be used to pause the particles.
sub_emitter
EntityPath sub_emitter = EntityPath("")
Path to another GPUParticles2D node that will be used as a subemitter (see ParticleProcessMaterial.sub_emitter_mode). Subemitters can be used to achieve effects such as fireworks, sparks on collision, bubbles popping into water drops, and more.
Note: When sub_emitter is set, the target GPUParticles2D node will no longer emit particles on its own.
texture
Texture2D texture
Particle texture. If null, particles will be squares with a size of 1×1 pixels.
Note: To use a flipbook texture, assign a new CanvasItemMaterial to the GPUParticles2D’s CanvasItem.material property, then enable CanvasItemMaterial.particles_animation and set CanvasItemMaterial.particles_anim_h_frames, CanvasItemMaterial.particles_anim_v_frames, and CanvasItemMaterial.particles_anim_loop to match the flipbook texture.
trail_enabled
bool trail_enabled = false
If true, enables particle trails using a mesh skinning system.
Note: Unlike GPUParticles3D, the number of trail sections and subdivisions is set with the trail_sections and trail_section_subdivisions properties.
trail_lifetime
float trail_lifetime = 0.3
The amount of time the particle’s trail should represent (in seconds). Only effective if trail_enabled is true.
trail_section_subdivisions
int trail_section_subdivisions = 4
The number of subdivisions to use for the particle trail rendering. Higher values can result in smoother trail curves, at the cost of performance due to increased mesh complexity. See also trail_sections. Only effective if trail_enabled is true.
trail_sections
int trail_sections = 8
The number of sections to use for the particle trail rendering. Higher values can result in smoother trail curves, at the cost of performance due to increased mesh complexity. See also trail_section_subdivisions. Only effective if trail_enabled is true.
use_fixed_seed
bool use_fixed_seed = false
If true, particles will use the same seed for every simulation using the seed defined in seed. This is useful for situations where the visual outcome should be consistent across replays, for example when using Movie Maker mode.
visibility_rect
Rect2 visibility_rect = Rect2(-100, -100, 200, 200)
The Rect2 that determines the node’s region which needs to be visible on screen for the particle system to be active.
Grow the rect if particles suddenly appear/disappear when the node enters/exits the screen. The Rect2 can be grown via code or with the Particles → Generate Visibility Rect editor tool.
Method descriptions
Section titled “Method descriptions”capture_rect
Rect2 capture_rect() const
Returns a rectangle containing the positions of all existing particles.
Note: When using threaded rendering this method synchronizes the rendering thread. Calling it often may have a negative impact on performance.
convert_from_particles
void convert_from_particles(particles: Entity)
Sets this node’s properties to match a given CPUParticles2D node.
emit_particle
void emit_particle(xform: Transform2D, velocity: Vector2, color: Color, custom: Color, flags: int)
Emits a single particle. Whether xform, velocity, color and custom are applied depends on the value of flags. See EmitFlags.
The default ParticleProcessMaterial needs to have ParticleProcessMaterial.particle_flag_preserve_color set to true to correctly use the color given from this function.
Additionally, it will use the contents of custom as (rotation, lifetime, animation, lifetime randomness).
Note: emit_particle() is only supported on the Forward+ and Mobile rendering methods, not Compatibility.
request_particles_process
void request_particles_process(process_time: float, process_time_residual: float = 0)
Requests the particles to process for extra process time during a single frame.
process_time defines the time that the particles will process while emitting is on. process_time_residual defines the time that particles will process with emitting turned off for the simulation. When combined with speed_scale set to 0.0, this is useful to be able to seek a particle system timeline.
restart
void restart(keep_seed: bool = false)
Restarts the particle emission cycle, clearing existing particles. To avoid particles vanishing from the viewport, wait for the finished signal before calling.
Note: The finished signal is only emitted by one_shot emitters.
If keep_seed is true, the current random seed will be preserved. Useful for seeking and playback.
