# XR Loader Automation

Managing XR loaders and plugins in Unity is often a source of **confusion and errors**—especially in multi-platform XR projects.\
XRBuildKit automates this process by handling **XR loader selection**, **plugin activation**, and **settings switching** whenever you load a device preset.

***

### What is XR Loader Automation?

**XR Loader Automation** ensures:

* ✅ Automatically enabling the correct XR SDKs/loaders (OpenXR, Oculus, XREAL, etc.) for each device/platform.
* ✅ Disabling incompatible loaders/plugins when switching presets.
* ✅ Preventing plugin conflicts and mismatched settings.
* ✅ Restoring all loader and plugin configurations when a Device Preset is loaded.

***

### Why is this Important?

* Unity **cannot run multiple competing loaders simultaneously** (e.g., Oculus + XREAL).
* Platform-specific plugins often **conflict** if both are active.
* Manual loader setup is **error-prone and time-consuming**.
* Loader conflicts may cause **broken builds or runtime errors**.

XRBuildKit guarantees only the **correct loaders and plugins** are active for the selected preset.

***

### How XRBuildKit Handles It

* Each **Device Preset** records the loader and plugin configuration when saved.
* On **LoadPreset**, XRBuildKit:
  * Restores only the correct XR loaders for the device/platform.
  * Calls `PluginConfigurator` to disable conflicting Android `.meta` plugin files.
  * Ensures Unity’s **XRGeneralSettings** and **XRManagerSettings** are updated cleanly.
* For **Android devices**:
  * Gradle templates, manifests, and AAR/so plugin files are **enabled/disabled automatically**.
  * XREAL support is handled via `.meta` modifications in `ConfigureXREALSupport`.

***

### Example Workflow

1. Save a preset for **Meta Quest 3 (Android)** with **OpenXR/Oculus loader enabled**.
2. Save another preset for **XREAL Air (Android)** with **XREAL loader + plugins enabled**.
3. Switch between presets in one click—XRBuildKit safely toggles loaders and plugins each time.

***

### API Example: PluginConfigurator

Developers can use the static API for automation or CI/CD build flows:

```csharp
using XRBuildKit.Editor.Utility;
using UnityEditor;

// Configure Android platform plugins for target device
PluginConfigurator.ConfigureAndroidPlatform("XREAL Air", BuildTarget.Android);

// Enable or disable XREAL support explicitly
PluginConfigurator.ConfigureXREALSupport(true); // enable
PluginConfigurator.ConfigureXREALSupport(false); // disable

// Disable all XR loaders (useful for headless/server builds)
PluginConfigurator.DisableAllXRLoaders(BuildTargetGroup.Standalone);
```

***

### Troubleshooting Loader Issues

* ❌ Still seeing loader conflicts?
  * Make sure you **loaded the correct Device Preset** before building.
* 🧹 Try a **Clean Build** to remove stale cached data.
* 🔍 Inspect `ProjectSettings/XRPackageSettings.asset` for leftover loader entries.
* ➕ Adding a new XR SDK? Save a new preset after configuring it in Unity Editor.

***

### Related Guides

* [Device Presets](https://chatgpt.com/c/device_presets_manual.md)
* [Building Your App with XRBuilderWindow](https://chatgpt.com/c/build_pipeline_manual.md)
* [Plugin Configuration & Android Management](https://chatgpt.com/c/PluginConfigurator.md)

***

🚀 **XR Loader Automation saves hours of debugging—letting you focus on XR content, not plugin conflicts.**
