# 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="/files/6AVCSNM8n5O5k5nS7W8a" 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`**


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.reneverse.io/publisher-flow/sdk-integration/unity/wip-using-the-unity-sdk/batch-serve-ad.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
