Skip to content

Initialize HealthBridge correctly

HealthBridge initialization is platform-specific. Android player builds require the HealthBridgeInitializer MonoBehaviour because Health Connect needs the current Android Activity and lifecycle.

using HealthBridge;
using UnityEngine;
public sealed class HealthBridgeBootstrap : MonoBehaviour
{
private async void Start()
{
bool ready = await HealthBridgeService.AutoInitializeAsync(
HealthBridgeSettings.Instance);
if (!ready)
Debug.LogWarning("HealthBridge is not ready.");
}
}

On iOS, you may call PrewarmAsync before a user-facing permission flow:

await HealthBridgeService.PrewarmAsync(HealthBridgeSettings.Instance);

Prewarming prepares HealthKit native work. It does not display the HealthKit authorization sheet.

  1. Add a GameObject to the first scene that uses health features.
  2. Add HealthBridgeInitializer.
  3. Assign the intended HealthBridgeSettings asset.
  4. Enable Initialize On Awake, or call await initializer.InitializeAsync() from your own flow.
  5. Keep the initializer alive for the Android lifecycle it owns.

HealthBridgeService.AutoInitializeAsync intentionally returns false in an Android player. Do not use it as an Android fallback.

using System.Threading.Tasks;
using HealthBridge;
using UnityEngine;
public sealed class HealthBridgeBootstrap : MonoBehaviour
{
[SerializeField] private HealthBridgeInitializer initializer;
public async Task<bool> InitializeAsync()
{
if (initializer != null)
return await initializer.InitializeAsync();
return await HealthBridgeService.AutoInitializeAsync(
HealthBridgeSettings.Instance);
}
}
  • Never call .Result or .Wait() on HealthBridge tasks from the Unity main thread.
  • Guard operations with HealthBridgeService.IsReady.
  • Subscribe to static events in OnEnable and unsubscribe in OnDisable.
  • Treat initialization failure as recoverable and keep unrelated gameplay usable.

In Play Mode, initialization should succeed with the editor provider. On Android, verify the initializer component—not AutoInitializeAsync—owns the request.