How to disable loop for ParticleEmitterComponent on visionOS?

297 Views Asked by At

In Reality Composer Pro there is a flag to toggle the loop of the particle system. In code I couldn't find a .loop value on the ParticleEmitterComponent - does anyone know how else I can disable the looping there?

2

There are 2 best solutions below

0
Mitemmetim On BEST ANSWER

To disable the loop you have to set the .timing value to once like this:

var particles = ParticleEmitterComponent()
particles.timing = .once(warmUp: 0, emit: .init(duration: 1))
0
Andy Jazz On

Besides the .once(...) case of the timing enum, you can use the fantastic burst() instance method which emits burstCount particles on the next update call. Here's the code:

import SwiftUI
import RealityKit

struct ContentView : View {
    @State var particles = ParticleEmitterComponent()
    let entity = Entity()
    
    var body: some View {
        VStack {
            Button("Burst") {
                particles.isEmitting = false     // important

                entity.components.remove(ParticleEmitterComponent.self)
                entity.components[ParticleEmitterComponent.self] = pSystem()
            }
            RealityView { content in
                content.add(entity)
            }
        }
    }       
    func pSystem() -> ParticleEmitterComponent {
        particles.emitterShape = .sphere
        particles.burstCount = 1500
        particles.burst()
        return particles
    }
}

enter image description here