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.
Write a workout
Section titled “Write a workout”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.
Write a generic sample
Section titled “Write a generic sample”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 app-created records
Section titled “Delete app-created records”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.
Safe interaction pattern
Section titled “Safe interaction pattern”- Explain what will be written.
- Require an intentional player action.
- Disable duplicate submission while a write is pending.
- Confirm
bSuccessbefore showing a saved state. - Preserve the UI record until deletion succeeds.
- Sanitize errors and never include health payloads in telemetry.
Test responsibly
Section titled “Test responsibly”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.
