Is there a particle system in RealityKit? if so, can someone point me to the correct documentation/articles?
So far I did not find any particle systems in the RealityKit module.
Is there a particle system in RealityKit? if so, can someone point me to the correct documentation/articles?
So far I did not find any particle systems in the RealityKit module.
@available(visionOS 1.0, macOS 15.0, iOS 18.0, *)
public struct ParticleEmitterComponent : Component, Codable
At WWDC'23, it was announced that RealityKit and Reality Composer Pro will get their own high-level Particle System with an accompanying set of parameters. For those who do not know what particles are, I could say that it's a 3D tool for creating and rendering such phenomena as rain, snow, flying dust and debris, fire, sparkles, smoke, fallen leaves, etc.
Here's my code for a Volume
initial scene type. Read this post if you need to change a Volume's size.
import SwiftUI
import RealityKit
struct ContentView: View {
var body: some View {
RealityView { content in
let model = ModelEntity()
model.components.set(particleSystem())
content.add(model)
}
}
func particleSystem() -> ParticleEmitterComponent {
var particles = ParticleEmitterComponent()
particles.emitterShape = .sphere
particles.emitterShapeSize = [1,1,1] * 0.05
particles.mainEmitter.birthRate = 2000
particles.mainEmitter.size = 0.05
particles.mainEmitter.lifeSpan = 0.5
particles.mainEmitter.color = .evolving(start: .single(.white),
end: .single(.cyan))
return particles
}
}
#Preview {
ContentView()
}
You can easily change/customize parameters of Particle System imported from Reality Composer Pro scene. Here's the code where I used a content of RealityView's update
closure:
import SwiftUI
import RealityKit
import RealityKitContent
struct ContentView: View {
var body: some View {
VStack {
RealityView { content in
if let scene = try? await Entity(named: "Scene",
in: realityKitContentBundle) {
content.add(scene)
print(scene)
}
} update: { content in
if let scene = content.entities.first {
let particles = scene.findEntity(named: "ParticleEmitter")
var particleComp = particles?.components[ParticleEmitterComponent.self]
particleComp?.speed = 0.5
particleComp?.mainEmitter.blendMode = .additive
particleComp?.mainEmitter.color = .constant(.single(.red))
particleComp?.mainEmitter.birthRate = 2000
particleComp?.mainEmitter.isLightingEnabled = true
particleComp?.mainEmitter.size = 0.2
particles?.components.set(particleComp!)
}
}
}
}
}
#Preview {
ContentView()
}
Additionally, you are capable of using SwiftUI's Model3D view to asynchronously load a .usdz
scene containing not only geometry but also our particles.
import SwiftUI
import RealityKit
struct ContentView: View {
var body: some View {
Model3D(named: "pEmitter.usdz") {
if let model = $0.model {
model
} else {
Color.clear
}
}
}
}
#Preview {
ContentView()
}
© 2022 - 2025 — McMap. All rights reserved.