Skip to main content
This topic shows example code of how to write an in-game event. When the event is fired, the event-based stats on the service are updated according to the stat rules that you’ve defined in Partner Center. Those stats, in turn, power event-based achievements.

Before you begin

  • Your product uses the full XBOX services feature set. New products start with limited XBOX services, and achievements and gamerscore aren’t available until your product is onboarded. For more information, see Request product onboarding to enable full XBOX services.
  • You configured the event, stat rules, and achievement in Partner Center and published the XBOX services configuration to your development sandbox.
  • Your dev kit or Windows PC uses the same development sandbox, and you sign in with a test account that has access to that sandbox. For more information, see XBOX services sandboxes overview.
  • Your game initialized the Gaming Runtime and then called XblInitialize with an XblInitArgs structure whose scid member contains your Service Configuration ID (SCID). The SCID is case-sensitive. For more information, see How to use XBOX services APIs.
  • You signed in a user and created an XblContextHandle for that user by calling XblContextCreateHandle.
To reset achievements and stats for a test account between test runs, use the Player Data Reset tool (XblPlayerDataReset.exe). To reset a player by XUID, the developer account that you sign in with by using XblDevAccount.exe needs the product-level Tools Access permission.

Write the event

The following example uses the flat C API. LogToScreen represents your app’s logging function.
For more information, see XblEventsWriteInGameEvent.

Troubleshooting

  • The call returns E_INVALIDARG. xboxLiveContext or the event name is null.
  • The call returns E_XBL_NOT_INITIALIZED. Call XblInitialize before you write events.
  • The call returns E_NOTIMPL. The XGameEvent feature of the Gaming Runtime isn’t available. On a Windows PC, the installed Gaming Runtime Services must include the XGameEvent feature.
  • The call succeeds, but the stat or achievement doesn’t change. The event name and the names of the event fields must match the names in your title’s service configuration. Names are case-insensitive. If the event name doesn’t match an event in the service configuration, the service drops the event without notifying your game.
  • Field values are in the wrong place. Put fields that have a finite set of numeric or string values, such as difficulty level or game mode, in the dimensions. Put scalar numeric metrics, such as score, time, or position, in the measurements.
  • Updates take time. Events are written locally on the device, even when the device is offline, and are uploaded when the device is online. If the device is online, event-based stats typically update 5 to 20 seconds after the event is written.
Last modified on October 29, 2026