SwiftUI RealitKit Attachments on a GameObject

Hi,

Is there any way to set a SwiftUI view as child to a game object?
I know we can get associated entity on swift using PolySpatialWindowManagerAccess.entityForIdentifier. Whenever I add an attachment to game object entity, it becomes invisible.

Does this happen with, for example, a simple Entity containing just a ModelComponent (perhaps initialized with just a sphere: entity.components.set(ModelComponent(mesh: .generateSphere(radius: 0.25), materials: [UnlitMaterial()])), or something to that effect, and then entity.setParent(unityEntity))? As far as I know, you should be able to add children or components to the entities created by Unity. We don’t ever, for example, remove components/children that aren’t created by our code.

However, I’m also not aware of a way to add SwiftUI views as children of RealityKit entities.

When I try the same behaviour with a sphere or box entity as you suggested, it just works. Whenever I try with the Attachment, it does not work.

For testing on Simulator, I use bounded volume including a cube. Then I create another window on swift which includes RealityKitView. Then I create attachment in that view (I could not find creating attachment without RealityKitView). Finally, I set the attachment as child of Unity game object (cube).

I’ll try the same behaviour on unbounded volume (MR). I’ll keep you informed.

Thanks!

1 Like

It is working! It was scaling issue coming from the Cube :person_facepalming:

1 Like