Skip to content

Write and delete health data

Writing health data changes the player’s health store. Enable it only for a clear product feature, request explicit write permissions, and provide an appropriate deletion path.

const int64 EndMs = FDateTime::UtcNow().ToUnixTimestamp() * 1000;
FHealthBridgeWorkoutWriteSample Workout;
Workout.ExerciseType = TEXT("Running");
Workout.Title = TEXT("Training Run");
Workout.StartTime = EndMs - 30 * 60 * 1000;
Workout.EndTime = EndMs;
Workout.bHasDistanceMeters = true;
Workout.DistanceMeters = 5000.0;
Workout.Location = EWorkoutLocationType::Outdoor;
FHealthBridgeService::WriteWorkout(
Workout,
[](const FHealthDataWriteResult& Result)
{
if (!Result.bSuccess)
{
// Keep the unsaved UI state and offer a safe retry.
}
});

StartTime and EndTime are UTC Unix milliseconds. Duration is derived. Prefer DistanceMeters for new code. Validate the exercise type before submission.

FHealthDataSample Sample;
Sample.DataTypeId = TEXT("steps");
Sample.StartTime = StartMs;
Sample.EndTime = EndMs;
Sample.Values.Add(TEXT("count"), TEXT("1200"));
FHealthBridgeService::WriteData(
FHealthDataWriteQuery(TEXT("steps"), Sample),
[](const FHealthDataWriteResult& Result) {});

Check registry write support, active-provider capability, and configured write permission before presenting a write action.

Delete by record ID only after a successful write or read confirms ownership:

FHealthBridgeService::DeleteData(
FHealthDataDeleteQuery::FromSample(Sample),
[](const FHealthDataDeleteResult& Result)
{
if (Result.bSuccess)
{
// Remove the record from UI only now.
}
});

HealthKit allows deletion only for objects written by the current app. Health Connect deletion is record-based. HealthBridge does not expose a broad time-range delete that could remove unrelated records.

  1. Explain what will be written.
  2. Require an intentional player action.
  3. Disable duplicate submission while a write is pending.
  4. Confirm bSuccess before showing a saved state.
  5. Preserve the UI record until deletion succeeds.
  6. Sanitize errors and never include health payloads in telemetry.

Use the disabled-by-default generated write/delete sandbox in the Blueprint examples. On devices, label synthetic records clearly and remove app-created test records after validation.