Skip to content

Unity Application Integration


Collect metrics data from Unity applications to visualize and analyze application performance.

Reading Path

Prerequisites

Note

If the RUM Headless service is already enabled, the prerequisites are automatically configured and you can integrate the app directly.

Application Integration

  1. Go to RUM > Create Application > Android/iOS
  2. Create two applications, one for Unity Android and one for Unity iOS, to receive RUM data from the Android and iOS platforms separately
  3. Enter the corresponding app name and application ID for each platform's application
  4. Select the application integration method:

    • Public DataWay: Receives RUM data directly; no DataKit collector installation required
    • Local environment deployment: Receives RUM data after the prerequisites are met

Install

Source Code: https://github.com/GuanceCloud/datakit-unity

Demo: https://github.com/GuanceCloud/datakit-unity/blob/dev/Assets/Scenes

  1. Download the latest ft-sdk-unity.unitypackage
  2. Import ft-sdk-unity.unitypackage via Assets -> Import Package -> Custom Package...
  3. Add the third-party JSON parsing library "com.unity.nuget.newtonsoft-json", which can be done via Package Manager -> Add Package by name ...
  4. Drag FTSDK.prefab into the first scene and initialize the SDK in the _InitSDK method in FTSDK.cs
  5. Drag FTViewObserver.prefab into other scenes to listen for page View lifecycle events, as well as application sleep and wake-up
  6. Use Application.logMessageReceived to listen for and convert Unity crash data and regular log data. For examples, see Quick Start and RUM Manual Tracking
Assets/Plugins
├── Android
│   ├── FTUnityBridge.java                // Android bridge
│   ├── InnerClassProxy.java              // Android Inner Setting Proxy
│   ├── ft-sdk-release.aar                // Android SDK
│   ├── gson-2.8.5.jar                    // Android SDK third-party dependency
├── iOS
│   ├── FTMobileSDK.xcframework           // iOS SDK
│   ├── FTUnityBridge.mm                  // iOS bridge
├── FTSDK.cs                              // Script bound to FTSDK.prefab
├── FTSDK.prefab                          // SDK initialization prefab
├── FTUnityBridge.cs                      // Unity bridge bridging methods for iOS, Android and other platforms
├── FTViewObserver.cs                     // Script bound to FTViewObserver.prefab
├── FTViewObserver.prefab                 // View page lifecycle listener prefab
├── UnityMainThreadDispatcher.cs          // Script bound to UnityMainThreadDispatcher.prefab
├── UnityMainThreadDispatcher.prefab      // Main thread consumption queue prefab
  • If the native Android and iOS projects have already integrated the native SDK, comment out the _InitSDK method to avoid duplicate setup. See Native and Unity Hybrid Development for the specific scenario
  • iOS Plugin Inspector setting: FTMobileSDK.xcframework is a dynamic library, so you need to select Add to Embedded Binaries. With this option selected, Unity will set the Xcode project option to copy the plugin file into the final application bundle.

unity_ios_plugin_embedded

If the native SDK has already been integrated, gson-2.8.5.jar and ft-sdk-release.aar for Android and FTMobileSDK.framework for iOS can be removed from the Unity project.
The OkHttp request and app launch time features on Android require ft-plugin. See Android SDK for detailed configuration.

Initialization Notes

For the minimal initialization example, see Quick Start.

For the full SDKConfig parameter description, see SDK Initialization.

Detailed Configuration Entry Points

Advanced Scenarios

FAQ

Adding Global Variables to Avoid Field Conflicts

To avoid conflicts between custom fields and SDK data, it is recommended to prefix tag names with your project abbreviation, for example custom_tag_name. For the key values used in the project, see the source code. If any SDK global variable has the same name as a variable in RUM or Log, RUM and Log override the SDK global variable.

Others

Feedback

Is this page helpful?