Manage your cookie settings. You can enable or disable different types of cookies below. For more details, see our Privacy Policy.

ParticleEffectComponent

1.5.0+

Native particle effect component.

This API might change in upcoming versions.

.TypeName: string 

.aliveCount: number 

Number of particles spawned with spawn and still alive (i.e. their lifetime hasn’t expired yet or was set to 0).

Can be passed to update.

.colors: null | AttributeAccessor<Float32ArrayConstructor

Get an attribute accessor to modify particle colors.

Returns: Color accessor or null, if particleEffect is not set.

Call update for changes to take effect.

.ids: null | Readonly<NumberArray

Get persistent IDs.

When using spawn, particle indices may change as particles expire. You can use IDs as persistent indices into external data or as seeds for generating random data per particle.

ID range is between 0 and maxCount. Values are unique for each particle within the component, but not globally.

Returns: Array of IDs or null, if particleEffect is not set.

.instanceData: null | AttributeAccessor<Float32ArrayConstructor

Get an attribute accessor to modify particle instance data.

Returns: Instance data accessor or null, if particleEffect is not set.

Call update for changes to take effect.

.lifetimes: null | AttributeAccessor<Float32ArrayConstructor

Get an attribute accessor to read or modify particle lifetimes.

First component is the elapsed lifetime, second component the total lifetime the particle was created with. Both are in seconds.

For convenient lifecycle management, prefer using spawn and aliveCount instead of manually modifying lifetimes. Changing lifetimes manually will stop spawn and aliveCount from working correctly.

Returns: Lifetime accessor or null, if particleEffect is not set.

Call update for changes to take effect.

.particleEffect: null | ParticleEffect 

Particle effect used by this component.

.particleEffect 

Set particle effect to use with this component.

.scalings: null | AttributeAccessor<Float32ArrayConstructor

Get an attribute accessor to modify particle scalings.

Scalings are in local space, analogous to setScalingLocal.

Returns: Scaling accessor or null, if particleEffect is not set.

Call update for changes to take effect.

.transforms: null | AttributeAccessor<Float32ArrayConstructor

Get an attribute accessor to modify particle transforms.

Transforms are in local space, analogous to setTransformLocal.

Returns: Transform accessor or null, if particleEffect is not set.

Call update for changes to take effect.

.spawn(count: number, lifetime: number, replacementPolicy: ParticleReplacementPolicy) ⇒ number 

Spawn new particles.

The spawned particles will always be at the end of the alive range so you can use aliveCount and the return value to get the index range:

1const count = comp.spawn(10, 5.0);
2const end = comp.aliveCount;
3const start = end - count;
4for (let i = start; i < end; ++i) {
5   // Initialize particle i
6}

Modifies values in lifetimes. Manually changing lifetimes will stop spawn and aliveCount from working correctly.

When particles expire or get replaced, remaining particles will get moved to ensure a contiguous range of alive particles. Use ids to track individual particles.

Returns: Number of spawned particles. Can be less than count if the maximum particle count was reached and the replacement policy is DontReplace.

ParamTypeDescription
countnumberNumber of particles to spawn.
lifetimenumberLifetime of the spawned particles, in seconds. If 0, the particles don’t expire.
replacementPolicyParticleReplacementPolicyPolicy to handle spawning when the maximum particle count is reached.

.update(count: number) ⇒ void 

Apply changes to transforms, scalings, lifetimes, colors and instanceData.

Uploads the updated particle attributes to the GPU.

Since this is an expensive operation, call it only once you have performed all modifications on a particle effect and avoid calling if you did not perform any modifications at all.

ParamTypeDescription
countnumberNumber of particles to update and render, clamped to maxCount.