Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

How to set the world alignment to gravity and heading for Roomplan?

So in the WWDC23 video on the Roomplan enhancement, it says that it is now possible to set a custom ARSession for the RoomCaptureSession. But how do you actually set the config for the custom ARSession?

init() {
      let arConfig = ARWorldTrackingConfiguration()
      arConfig.worldAlignment = .gravityAndHeading
      arSession = ARSession()
      roomCaptureView = RoomCaptureView(frame: CGRect(x: 0, y: 0, width: 42, height: 42), arSession: arSession)
      sessionConfig = RoomCaptureSession.Configuration()
      roomCaptureView.captureSession.delegate = self
      roomCaptureView.delegate = self
  }

However, I keep getting an issue that self is being used in the property access before being initialised. What can I do to fix it?

Answered by Riptide314 in 796598022

Had to move some code around to get it to work. I think the main issue was declaring arSession as a class variable instead of within the initialiser.

class RoomCaptureController: RoomCaptureViewDelegate, RoomCaptureSessionDelegate, ObservableObject
{
    var roomCaptureView: RoomCaptureView
    var sessionConfig: RoomCaptureSession.Configuration
  
    init() {
        roomCaptureView = RoomCaptureView(frame: CGRect(x: 0, y: 0, width: 42, height: 42))//, arSession: arSession)
        sessionConfig = RoomCaptureSession.Configuration()
        let arConfig = ARWorldTrackingConfiguration()
        arConfig.worldAlignment = .gravityAndHeading
        roomCaptureView.captureSession.arSession.run(arConfig)
        roomCaptureView.captureSession.delegate = self
        roomCaptureView.delegate = self     
    }
}
Accepted Answer

Had to move some code around to get it to work. I think the main issue was declaring arSession as a class variable instead of within the initialiser.

class RoomCaptureController: RoomCaptureViewDelegate, RoomCaptureSessionDelegate, ObservableObject
{
    var roomCaptureView: RoomCaptureView
    var sessionConfig: RoomCaptureSession.Configuration
  
    init() {
        roomCaptureView = RoomCaptureView(frame: CGRect(x: 0, y: 0, width: 42, height: 42))//, arSession: arSession)
        sessionConfig = RoomCaptureSession.Configuration()
        let arConfig = ARWorldTrackingConfiguration()
        arConfig.worldAlignment = .gravityAndHeading
        roomCaptureView.captureSession.arSession.run(arConfig)
        roomCaptureView.captureSession.delegate = self
        roomCaptureView.delegate = self     
    }
}
How to set the world alignment to gravity and heading for Roomplan?
 
 
Q