Skip to content

Unity quickstart

Use Unity 6. The HealthBridge package supports iOS HealthKit and Android Health Connect; editor and desktop runs use the mock provider rather than real health records.

  1. Import the supplied HealthBridge .unitypackage into the Unity project. Unity resolves the required Newtonsoft JSON dependency on first import.
  2. Let script compilation finish. The HealthBridge Setup Wizard should open. If it does not, select Window > HealthBridge > Setup Wizard.
  3. In the wizard, create a HealthBridge Settings asset and optional editor test data. Select only the data types your feature needs.
  4. Review the settings later at Edit > Project Settings > HealthBridge.

For Android, add a HealthBridgeInitializer component to a scene GameObject, assign the settings asset, and enable Initialize On Awake. It supplies the activity lifecycle the Android provider needs.

For platforms other than Android, use automatic initialization:

using HealthBridge;
using UnityEngine;
public class HealthBridgeBootstrap : MonoBehaviour
{
private async void Start()
{
var ready = await HealthBridgeService.AutoInitializeAsync();
Debug.Log(ready ? "HealthBridge is ready" : "HealthBridge is not ready");
}
}

On iOS, await HealthBridgeService.PrewarmAsync() before a permission flow can reduce first-use native setup work. It is a no-op on other platforms.

  1. Create or copy the Health Data Review sample into your project.
  2. Enter Play mode and use the sample’s Workouts, Heart Rate, Health Data, and Write tabs.
  3. Confirm that initialization succeeds and mock data is shown.

The mock provider is for development only. Continue with mobile platform setup before treating an editor result as device validation.

Use a short unified type ID with HealthDataQuery:

using HealthBridge;
using HealthBridge.Data;
var query = new HealthDataQuery("steps", daysBack: 7, maxRecords: 100);
var result = await HealthBridgeService.ReadDataAsync(query);
foreach (var sample in result.Samples)
Debug.Log($"{sample.DataTypeId}: {sample.StartDateTime}");

Common type IDs include steps, sleep, weight, calories, distance, nutrition, hydration, and exercise. The selected settings permissions, not just the code, determine which platform data can be requested.

  • The OS prompt is shown during initialization. Present your own explanation to the player before calling it.
  • iOS may report initialization as complete even when access was denied; Apple does not expose per-type read grants. Denied reads can appear as empty data.
  • Android initialization succeeds only when its core permissions are granted. Subscribe to HealthBridgeEvents.OnPermissionsResolved for the granted and denied details.

Next: configure iOS and Android or troubleshoot setup.