Runtime access to build version and git metadata.
Key Points:
- Requires
version-data.txtTextAsset inResources/(resource name:VersionServices.VersionDataFilename) VersionEditorUtilswritesAssets/Configs/Resources/version-data.txton editor load and before builds; it uses git CLIVersionExternalis always safe (readsApplication.versiondirectly, no load required)- Auto-bootstrap: version metadata loads automatically at
[RuntimeInitializeOnLoadMethod(SubsystemRegistration)], before any sceneAwakeand before vendor-SDKSubsystemRegistrationcallbacks that read it (e.g. Sentry's Option Config Script). Consumers do not need to callLoadVersionData()/LoadVersionDataAsync()explicitly for the default flow. - Lazy-load fallback:
VersionInternal/Branch/Commit/BuildNumbergetters triggerLoadVersionData()on first access if the auto-bootstrap hook has not yet fired. Covers the case where a sibling SDK'sSubsystemRegistrationcallback fires before this package's (assembly ordering between[RuntimeInitializeOnLoadMethod]callbacks at the same phase is undefined). - Graceful degradation: if
version-data.txtis missing fromResources/,VersionInternalfalls back toApplication.versionand the other accessors returnstring.Empty. No exception is raised. LoadVersionData()(sync) andLoadVersionDataAsync()(async) remain available for callers that want to pre-warm explicitly. Both are idempotent and share the same parse/assign pipeline; pick async only if you've extendedVersionDatawith large blobs that would noticeably stall the main thread.
using GameLovers.Services;
// No setup call needed — auto-bootstrap fires at SubsystemRegistration.
// Optional pre-warm if you want to control timing explicitly:
// VersionServices.LoadVersionData();
// await VersionServices.LoadVersionDataAsync();
// Safe at any time — reads Application.version directly.
string externalVersion = VersionServices.VersionExternal; // "1.0.1"
// Auto-loaded; lazy-loads on first access if SubsystemRegistration race occurred.
string internalVersion = VersionServices.VersionInternal; // "1.0.1-42.main.abc123"
string branch = VersionServices.Branch; // "main"
string commit = VersionServices.Commit; // "abc123"
string buildNumber = VersionServices.BuildNumber; // "42"
// Check if app is outdated against a remote version string
bool outdated = VersionServices.IsOutdatedVersion("1.2.0");| Call | Behaviour | Condition |
|---|---|---|
VersionInternal |
Falls back to Application.version |
version-data.txt missing from Resources/ or fails to parse |
Branch, Commit, BuildNumber |
Return string.Empty |
version-data.txt missing from Resources/ or fails to parse |
A Debug.LogError is emitted when load fails. None of the accessors throw.