Custom component question

I created a custom component for composer pro in which I have several variables I need an entity to have.

The idea is to add this component to some 3d models and save them as usdz’s then I load these usdz’s in code and do specific things depending on these variables.

The component shows up in composer fine and I can set variables there. The problem is that the values I set in composer are different that what is shown in code. lets say in composer I set canMove = true. then when I read in code is set to false. I don’t know if I’m missing something

public struct MyObjectComponent: Component, Codable
{
    public var affectAll: Bool = false
    public var affectFloor: Bool = false

    public var canMove: Bool = false
    public var moveX: Bool = false
    public var moveY: Bool = false
    public var moveZ: Bool = false

    public var canRotate: Bool = false
    public var rotateX: Bool = false
    public var rotateY: Bool = false
    public var rotateZ: Bool = false

    public init() {
        
    }  
}

Any help appreciated.

Guillermo

Hello @gl5 ,

What you are describing should work: when you create a custom component as you have done, attach it to an Entity and set the value of one of the component properties in Reality Composer Pro, you should be able to read those values after loading the Entity.

A few things to check:

  • Have you registered the component? You must call MyObjectComponent.registerComponent() somewhere in your project (such as the initializer for your view).
  • If you set up a simple Timeline animation to trigger via an an OnAddedToScene Behavior (something simple, just a test), can you verify that it plays? This will make sure you are editing the right scene file, and that RCP is saving your changes correctly.
  • Can you verify that the Entity you are looking at after you load your scene is the same Entity you edited in RCP? Sometimes .findEntity(named:) doesn't behave as expected when multiple entities share the same name.

I have double checked on my end, and I am able to set boolean values on MyObjectComponent in RCP that are maintained after the entity is loaded at runtime.

Could you share more about your project environment, such as OS, SDK, Xcode version numbers, and the code you are using to load your entity and read the component? It is possible that something strange has happened to your project that is causing you to encounter a bug, in which case I encourage you to file a bug report using Feedback Assistant.

Let me know if you have any questions!

Hi,

Here is more information.

Xcode: Version 16.0 (16A242d)

Composer Pro: Version 2.0 (448.0.16.0.3)

VisionOS: 2.0

I tried the component 2 ways.

Model A: In composer add the component, set some values as not to use the default ones, to a 3d model and export that model as a usdz

Model B: In composer add the component to a simple cub that will be part of the scene. Also setting some values as to not use the default ones.

The component is registered in the app main, init with

RealityKitContent.MyObjectComponent.registerComponent() Or. not sure what the difference is but its the same result. MyObjectComponent.registerComponent()

Then in the immersiveView

var body: some View
{
    RealityView { content, attachments in
\\......

after everything is setting up

I print the entities in the scene with that component including the one inserted from the usdz

For model A: all the values are different. Some are false, some are true. Not idea where that comes from, it's not what I setup in composer

For model B: all the values are at their default false, not what I set in composer

I can add the component manually in code, set values and it works correctly, but I want to be able to set the values in composer as I will be exporting these usdz’s

Thanks @gl5 , I think I understand a bit more about your context now.

The USDZ export functionality in Reality Composer Pro (File > Export... from the menu bar) may not be what you want to use. Is there a specific reason you are using the export functionality of RCP? Keep in mind:

  • Xcode projects (RealityKit) can already read the files you create and edit in RCP. They are USDA files, which is a human-readable and source-control-friendly version of the USD format.
  • Importing USDZ that has been exported from RCP may lead to duplication of assets like textures, since dependencies are likely to be included in USDZ files.
  • USD exported from RCP will contain Apple-specific data that is unlikely to be compatible with other software (such as the serialized data for your custom component).

You may be encountering undocumented behavior when reading your exported USD files, but I think if you avoid exporting the files from RCP in the first place this should not be an issue. If you do need to use RCP as some sort of intermediate tool for your workflow, I would love to understand more about what you are trying to do, since this may be a candidate for an enhancement request using Feedback Assistant.

Thank you for your question!

These models I’m preparing and then exporting are actually in its own composer pro project, not in the one included in xcode.

The app will load models (usdz) from a cloud service at run time, and I need these models to have certain properties so it can work with other stuff in the app and with other usdz’s. That’s why they have this custom component so they can interact correctly when the user inserts these models into their session.

Does this make sense ? 🙂

Custom component question
 
 
Q