Multi-user AR

Skills

RealityKit

ARKit

Swift

Multipeer Connectivity

This enables multi-user AR with Multipeer Connectivity, RealityKit synchronization, and an ARKit collaborative session.

#RealityKit #ARKit #Swift #MultipeerConnectivity #Experiment

What it shows

Two phones look at and move the same virtual furniture at the same time. A sofa, table, television, and TV stand stay in one shared room while either person drags or rotates a piece.


Joining the room

Nearby phones find each other with Multipeer Connectivity. MultipeerHelper advertises and browses the helper service, and refuses a peer whose iOS collaboration token does not match.

  • World tracking looks for horizontal planes. Collaboration is on, so ARKit can build a shared map.

  • Each device archives ARSession.CollaborationData and sends it to every peer. Incoming data is applied with session.update(with:).

  • The phones need to be held side by side. When an ARParticipantAnchor appears, the peer is localized and the room can be placed.

  • RealityKit synchronization uses MultipeerConnectivityService as the scene synchronizationService.


The furniture

After the peer is localized, a tap adds the living-room scene. The television is parented to the TV stand. Rotation and translation gestures are installed on the sofa, table, television, and stand.

  • The heavy model entities are not synchronized. Each phone loads the same Reality file locally, turns synchronization off on those models, and parents them to the synced entities when those entities arrive.

  • A short delay removes a duplicate copy of the scene if both phones add one.

  • LiDAR devices turn on mesh reconstruction. Environment texturing is automatic. Depth of field and motion blur are off.


Who can move it

A touch on a piece the phone does not own calls requestOwnership. When ownership is granted, that phone installs the gestures and tells the other peer. The scene’s transfer mode is autoAccept, so the handoff does not wait for a manual approval.

Create a free website with Framer, the website builder loved by startups, designers and agencies.