# Batch Serve Ad

### :pancakes: About Batch Serve Ad

The Batch Serve Ad functionality makes it easy to populate multiple ad surfaces across scenes in one go—perfect for efficient ad management at scale.

#### **🌍 Global Registration**

All ad surfaces are **automatically registered** globally once instantiated—no manual work required. Just place them in your scene, and the SDK takes care of the rest.

### **📦 How It Works**

1. **Batch Request**: A single request is sent to the server, asking for ad content for all registered surfaces.
2. **Even Distribution**: Ads are returned and evenly assigned to all eligible ad surfaces.
3. **Gizmos in Editor**: When selecting an ad surface in the editor, gizmos appear to help visualize ad placement and orientation.

***

### **🧪 Preview in Unity Editor**

You can trigger batch serving directly from the editor via:\
\&#xNAN;**`Window → ReneVerse → BatchServeAd`**

<figure><img src="https://2133953908-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2R0efebFfiw8qumiNT9v%2Fuploads%2FOJhNwnAk2hZvdPRowoKW%2FBatch%20Serve%20Ad.gif?alt=media&#x26;token=903e031a-84ad-4a10-b0f0-569770d09196" alt=""><figcaption><p>BatchServeAd is only available in Play Mode.</p></figcaption></figure>

***

### **🧑‍💻 Runtime Integration**

#### **Example 1 – Simple Scene Use:**

```
using ReneVerse;
using UnityEngine;

public class InSceneScript : MonoBehaviour
{
    private void Awake()
    {
        ReneAPIManager.BatchServeAd();
    }
}
```

#### Example 2 – During Transition from Another Scene:

<pre><code>using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; using UnityEngine.SceneManagement; 
using ReneVerse;

public class LoadingManagerExample : MonoBehaviour {
public string nextSceneWithAdSurfaces; 
public GameObject loadingScreen;
<strong>
</strong><strong>private void Start()
</strong>{
    StartCoroutine(LoadSceneAndBatchServeAdCoroutine());
}

private IEnumerator LoadSceneAndBatchServeAdCoroutine()
{
    // Display the loading screen
    loadingScreen.SetActive(true);

    // Load the next scene asynchronously
    AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(nextSceneWithAdSurfaces);

    // Wait until the asynchronous scene fully loads
    while (!asyncLoad.isDone)
    {
        yield return null;
    }

    // Ensure all ad surfaces are registered

    // Call the batch serve ad function asynchronously
    yield return BatchServeAdWrapper();

    // Hide the loading screen
    loadingScreen.SetActive(false);
}

private IEnumerator BatchServeAdWrapper()
{
    var task = ReneAPIManager.BatchServeAd();
    while (!task.IsCompleted)
    {
        yield return null;
    }

    if (task.Exception != null)
    {
        Debug.LogError($"BatchServeAd failed: {task.Exception}");
    }
}
}
</code></pre>

### **❌ Batch Disable Ads**

Need to clear ads all at once—for example, during testing? You can disable all currently served ads using:

```csharp
ReneAPIManager.BatchDisableAds();
```

Or directly from the editor:\
\&#xNAN;**`Window → ReneVerse → BatchDisableAds`**
