実装メモ:Reality Composer Pro で定義したパーティクルを Reality View のエンティティにアタッチする

visionOS/App プロジェクトを作成したら初期状態で存在する Packages/RealityKitContent/Package を Reality Composer Pro で開き、以下のブログに従ってパーティクルを追加する。

How to make a fire effect using particles and Reality Composer Pro

これを実装で抽出し、任意のエンティティに追加する。

func attachParticleEffect(to entity: Entity) async throws {
    let particlesRoot = try await Entity(
        named: "ParticleEffect",
        in: realityKitContentBundle // already defined in Packages/RealityKitContent/Sources/RealityKitContent/RealityKitContent.swift
    )
    guard
        let emitterSourceEntity = particlesRoot.findEntity(named: "ParticleEmitter"),
        let emitterComponent = emitterSourceEntity.components[ParticleEmitterComponent.self]
    else {
        assertionFailure("Emitter entity or ParticleEmitterComponent not found")
        return
    }
    entity.components.set(emitterComponent)
}

検証環境 Xcode 26.0.1 (17A400)

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny