Having an issue with using a custom component with Reality Composer Pro

We have a project which is currently being built as a XCFramework.

The framework contains a custom component to be used with entities in Reality Composer Pro.

I have tried to se set the RCP Package.swift file to reference the framework package for the in the dependancies.

Nothing that I do with the folder path to reference the code is working.

Do I need to change the project to be using Swift source code instead of a XCFramework?

The component needs to be in the framework as there is a class in the framework that works directly with the custom compoent.

I am able to reference the XCFramework as a Swift Package with other projects.

I was typing up the original post over a very slow internet connection so their some wonky grammar.

I have been modifying the Package.swift file for the Reality Kit project & I have been using relative paths but it does not work for some reason.


let package = Package(
    name: "RealityKitContent",
    platforms: [
        .visionOS(.v2),
        .macOS(.v15),
        .iOS(.v18)
    ],
    products: [
        // Products define the executables and libraries a package produces, and make them visible to other packages.
        .library(
            name: "RealityKitContent",
            targets: ["RealityKitContent"]),
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages this package depends on.
        .target(
            name: "RealityKitContent",
            dependencies: []),
    ]
)

I tried setting a path like

    dependencies: [
        .package(path: "../../../../MyFramework"),
    ],
    targets: [
        .target(
            name: "RealityKitContent",
            dependencies: [
                .product(name: "MyFramework", package: "MyFramework")
            ]),
    ]

At this time, the Swift package Framework is being referenced as a local package. Eventually, there will be a public GitHub repo.

Hi @Miro

Components in a framework will not show up in Reality Composer Pro.If your goal is to encapsulate your System in a framework, you can get close using the following approach.

  • In your framework, define a protocol for the component and a system, that takes a generic that implements the component protocol.
  • Instruct people who use your framework to create a component that implements the protocol, register that component and the system, passing it that component.

For example, if you want your framework to contain a reusable Bubble system you would follow these steps:

In BubbleFrameworkdefine BubbleComponentProtocol and BubbleSystem.

protocol BubbleComponentProtocol : Component, Codable {
    var burst:Bool {get}
    var direction:simd_float3 {get}
}

struct BubbleSystem<T:BubbleComponentProtocol>: System {
  let query = EntityQuery(where: .has(T.self))
   
  public init(scene: Scene) {
  }

  public func update(context: SceneUpdateContext) {
    let bubbles = context.entities(matching: self.query,
                    updatingSystemWhen: .rendering)

    for bubble in bubbles {
      guard let component = bubble.components[T.self] else {continue}
       
      // do things with the bubble component
    }
  }
}

In the consuming app's Reality Composer Pro package, add a dependency to BubbleFramework then implement BubbleComponentProtocol.

public struct BubbleComponent : BubbleComponentProtocol, Codable {
    var burst = false
    var direction:simd_float3 = [0.1, 0.1, 0.1]
}  

In the app, that uses the RCP package, register the component and system in the app's initializer.

BubbleComponent.registerComponent()
BubbleSystem<BubbleComponent>.registerSystem()

BubbleComponent should now appear in Rwaking Composer Pro.

Please accept this answer if it answers your question. If you need more help, please follow up so I can help you achieve your goal.

Having an issue with using a custom component with Reality Composer Pro
 
 
Q