I have a visionOS app where I instantiate ARKitSession and various providers (HandTrackingProvider and WorldTrackingProvider) in my appModel. That way, I can pass these providers to a Task which runs a gRPC server for sending the data from these providers to a client. When the users enters the immersive space of the app, the ARKitSession will run the providers if they are not running already.
I am now trying to implement the AccessoryTrackingProvider with the PSVR sense controllers but it does not fit with my current framework because the controllers may not be connected when the ARKitSession.run function is called. So I need to find a new place to start the session.
My question is, if I already have a session which is running the hand and world tracking providers, can I start another session to run the accessory tracking? Should they all be running on the same session?
Is there a way to stop the session and restart it when the controllers are connected? When I tried this, I get an error that says "It is not possible to re-run a stopped data provider (<ar_hand_tracking_provider_t: " but if I instantiate a new HandTrackingProvider, then the one that got passed to the gRPC task would no longer be the one running in the new session.
Any advice on how best to manage the various providers and ARKit sessions would be greatly appreciated.
Hi @ericD_TRI
You're correct that you can run multiple instances of ARKitSession, and this is actually a fine approach for your use case. Here's how I'd recommend structuring it:
Use Two Separate ARKitSession Instances:
- Primary Session: For
HandTrackingProviderandWorldTrackingProvider- start this when entering the immersive space - Accessory Session: For
AccessoryTrackingProvider- start this dynamically when controllers are detected
Regarding Provider Reuse:
The error you encountered is correct - once a provider is stopped, it cannot be rerun. However, you can create new instances of both the ARKitSession and the providers. For your gRPC server integration, you'll need to update the provider references when you create new instances.
Example Implementation Strategy:
- Keep your existing session for hand/world tracking as-is
- Create a separate session management system for accessory tracking that:
- Monitors for controller connectivity
- Creates a new
ARKitSession+AccessoryTrackingProviderwhen controllers connect - Updates your gRPC server's provider references accordingly
- Properly cleans up the accessory session when controllers disconnect
This approach gives you the flexibility to handle the dynamic nature of accessory connections while maintaining stable hand and world tracking throughout your app's lifecycle.