Skip to content
UCIK Docs
Esc
↑↓navigate↵open⌘Jpreview
On this page

Record game events

Send useful gameplay and diagnostic events through the configured service.

Configure CloudWatch or another registered telemetry provider. Ask the player before recording: unanswered consent is treated as no, and the choice is stored on this machine.

Record an event

Record a match event
Record a match event
Preparing your graph…

Loading the interactive viewer.

Record match duration
Record match duration
Preparing your graph…

Loading the interactive viewer.

Game module dependencies: UCIKCore, BetideCore.

#include "Engine/GameInstance.h"
#include "Telemetry/UCIKTelemetrySubsystem.h"
#include "UCIKCore.h"

void SaveTelemetryChoice(UGameInstance &GameInstance, bool PlayerAgreed)
{
    if (auto *Telemetry = GameInstance.GetSubsystem<UUCIKTelemetrySubsystem>())
        Telemetry->SetConsent(PlayerAgreed);
}

bool NeedsTelemetryChoice(UGameInstance &GameInstance)
{
    const auto *Telemetry = GameInstance.GetSubsystem<UUCIKTelemetrySubsystem>();
    return Telemetry && !Telemetry->HasAnsweredConsent();
}

void RecordMatchStarted(UGameInstance &GameInstance)
{
    auto *Telemetry = GameInstance.GetSubsystem<UUCIKTelemetrySubsystem>();
    if (!Telemetry || !Telemetry->HasConsent())
        return;
    const FBetideError Error =
        Telemetry->RecordEvent(TEXT("MatchStarted"), TEXT("{\"mode\":\"Coop\"}"), false);
    if (Error.IsError())
    {
        UE_LOG(LogUCIK, Warning, TEXT("%s"), *Error.GetLogString());
    }
}
void RecordMatchDuration(UGameInstance &GameInstance, double DurationSeconds)
{
    auto *Telemetry = GameInstance.GetSubsystem<UUCIKTelemetrySubsystem>();
    if (!Telemetry || !Telemetry->HasConsent())
        return;
    const FBetideError Error =
        Telemetry->RecordMetric(TEXT("MatchDurationSeconds"), DurationSeconds, {});
    if (Error.IsError())
        UE_LOG(LogUCIK, Warning, TEXT("%s"), *Error.GetLogString());
}

The personal-data flag describes the payload; it does not remove personal data. Avoid putting tokens, credentials, or unnecessary player details in event JSON.

Flush queued records

Flush queued records
Preparing your graph…

Loading the interactive viewer.

Game module dependencies: UCIKCore, BetideCore.

#include "Engine/GameInstance.h"
#include "Telemetry/UCIKTelemetrySubsystem.h"
#include "UCIKCore.h"

void FlushGameTelemetry(UGameInstance &GameInstance)
{
    auto *Service = GameInstance.GetSubsystem<UUCIKTelemetrySubsystem>();
    if (!Service)
        return;

    Service->Flush(
        FBetideCallback<bool>::CreateWeakLambda(&GameInstance, [](const TBetideResult<bool> &Result) {
            if (!Result.bOk)
            {
                UE_LOG(LogUCIK, Warning, TEXT("%s"), *Result.Error.GetLogString());
                return;
            }
            UE_LOG(LogUCIK, Log, TEXT("Telemetry flushed: %d"), Result.GetValue());
        }));
}

Recording can queue a provider upload. Flush at a suitable checkpoint and handle failure; do not assume an asynchronous request finishes after the process exits. Revoking consent stops new records. Without consent, records are dropped rather than saved for later consent.

Was this page helpful?