RealityView in Xcode 15.0 beta 8 gives error - 'init(make:update:attachments:)' is unavailable in visionOS

My code was working in beta 7 but since I updated I'm getting the following error when trying to init a RealityView 'init(make:update:attachments:)' is unavailable in visionOS

I'm using:

RealityView { content, attachments in
    // Code ...
} update: { content, attachments in
    // Code ...
} attachments: {
    // Code ... 
}

Accepted Reply

As far as I can tell this big change went undocumented but the way attachments work completely changed:

Old:

RealityView { content, attachments in
    content.add(Entity())
} attachments: {
    Text("Hello")
        .tag("h1")
}

New:

RealityView { content, attachments in
    content.add(Entity())
} attachments: {
    Attachment(id: "h1") {
        Text("Hello")
    }
}

Definitely an improvement but I hope it get’s added to the change log soon! Or at least get’s a helpful warning in the next Xcode! (edited)

  • @warpling how are you able to figure something like this out? I'd love to be able to come to such a conclusion myself on a future beta release. I wonder which documents you looked at to know this one. : )

  • @mesqueeb I found out about the Attachment(id:) fix on the Apple Vision Pro Discord https://discord.gg/D8jf4anD On the #developer channel, we spent an hour trying to figure why attachments no longer worked in the new Xcode beta, and one of the developers happened to type Attachment and got lucky with Xcode autocomplete.

Add a Comment

Replies

As far as I can tell this big change went undocumented but the way attachments work completely changed:

Old:

RealityView { content, attachments in
    content.add(Entity())
} attachments: {
    Text("Hello")
        .tag("h1")
}

New:

RealityView { content, attachments in
    content.add(Entity())
} attachments: {
    Attachment(id: "h1") {
        Text("Hello")
    }
}

Definitely an improvement but I hope it get’s added to the change log soon! Or at least get’s a helpful warning in the next Xcode! (edited)

  • @warpling how are you able to figure something like this out? I'd love to be able to come to such a conclusion myself on a future beta release. I wonder which documents you looked at to know this one. : )

  • @mesqueeb I found out about the Attachment(id:) fix on the Apple Vision Pro Discord https://discord.gg/D8jf4anD On the #developer channel, we spent an hour trying to figure why attachments no longer worked in the new Xcode beta, and one of the developers happened to type Attachment and got lucky with Xcode autocomplete.

Add a Comment

Yes! Wrapping my attachments in Attachment(id:){} worked. I would have never guessed this would have been the solution with that terrible error message so thanks for your help.

  • Yeah, those error messages really suck.

Add a Comment

Thanks for mentioning the update in RealityView, guess this was missed out in the latet Release Notes

  • Very helpful! I also checked Release Note without finding any details. Probably missed by the team!

Add a Comment

Same here! Thanks warpling for your advise.

With this update, Button and Toggle attachments oftentimes don't fire on first load in an immersive space. They always seem to work when the same immersive space is loaded again. Smells like a race condition. I can reproduce this with Xcode's visionOS template project.

  • Filed this with sample code demonstrating the issue as FB13121010.

  • I found a workaround for this issue which I posted in another thread.

Add a Comment

Apple should clearly communicate these changes. I just got the error message: "attachments" not available on visionOS. What the ...?