Assets/StarterSamples/Usage/Tools/ and open Firebase.unity. Before building, import the Firebase Unity SDK packages and replace the placeholder google-services.json with your configuration file from Firebase Console. Enable the Firebase sample through Meta > Samples > Firebase > Enable Firebase Sample. Build and deploy to your Quest device using Meta Quest Developer Hub or Unity’s build tools.| File / Scene | What it demonstrates | Key concepts |
|---|---|---|
Firebase.unity | Complete Firebase integration scene | OVRCameraRig prefab for VR tracking, DebugUIBuilder for runtime panels, and three Firebase GameObjects (StartCrashlytics, SampleUI, AnalyticsUI) |
StartCrashlytics.cs | Firebase SDK initialization | Async dependency verification, continuation-based flow control, app instance field to prevent garbage collection |
AnalyticsUI.cs | Firebase Analytics API usage | Custom event logging with typed parameters, user ID and property assignment, analytics collection control, session timeout configuration |
SampleUI.cs | Firebase Crashlytics API usage | Crash log recording, non-fatal exception logging, custom key-value metadata via SetCustomKey(), user ID tracking, collection control via IsCrashlyticsCollectionEnabled property |
FirebaseEnabler.cs (Editor) | Conditional compilation setup | Scripting define symbol management for Android builds, menu integration for enabling Firebase support |
StartCrashlytics.cs calls FirebaseApp.CheckAndFixDependenciesAsync() in the Start() method and chains a continuation to check the DependencyStatus. The app instance is stored as an instance field to prevent garbage collection during the app lifecycle.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
if (task.Result == DependencyStatus.Available) {
app = FirebaseApp.DefaultInstance;
}
});
Assets/StarterSamples/Usage/Tools/Firebase/StartCrashlytics.cs.AnalyticsUI.cs builds parameter arrays dynamically based on user input. The code demonstrates how to create Parameter objects with different data types and pass them to FirebaseAnalytics.LogEvent(). Notice how the dynamic parameter system uses reflection on DebugUIBuilder internals to add and remove UI fields at runtime.Assets/StarterSamples/Usage/Tools/Firebase/AnalyticsUI.cs.SampleUI.cs shows how to call Crashlytics.SetCustomKey() and Crashlytics.SetUserId() to tag crash reports with identifying information. The sample also includes a deliberate crash trigger using unsafe pointer dereferencing for testing crash reporting integration.Assets/StarterSamples/Usage/Tools/Firebase/SampleUI.cs.OVR_SAMPLES_ENABLE_FIREBASE scripting define symbol to guard all Firebase code behind conditional compilation. The sample compiles without errors when the Firebase SDK packages are not present. The editor script FirebaseEnabler.cs manages this define symbol through a menu interface, setting it only for the Android build target.Assets/StarterSamples/Core/Tools/Firebase/Editor/FirebaseEnabler.cs.