# Troubleshoot

### Ad Loading Failed <a href="#id-6ebe3b5a-e6da-4390-b370-a348944ef7e3" id="id-6ebe3b5a-e6da-4390-b370-a348944ef7e3"></a>

<div align="left"><figure><img src="https://content.gitbook.com/content/C4pLAW1WW2c9V2Kogh1z/blobs/upf9zV1ND9c1DPZ2e96d/Screenshot_20240205-145155.jpg" alt="" width="375"><figcaption></figcaption></figure></div>

1. Make sure you have added the App ID inside the Google Ad Mob settings window.
2. In the case of live ad id (Test mode off), this may happen if there is no fill from the Google server.
3. You might run into this issue when using Unity Editor Version 2021 or above with Admob versions 9.6.0. To fix this, make sure you are building your application with IL2CPP as your scripting backend.

### No Impression but Click <a href="#id-75d19063-242b-486e-b874-ed3aeb011c24" id="id-75d19063-242b-486e-b874-ed3aeb011c24"></a>

1. If it’s a 3d game the camera and the ad unit must be on the side + Z world axis to get an impression.
2. Make sure there is no collider between the main camera and the ad Unit.
3. If you are instantiating ad prefabs in real-time try disabling the strip engine code option from the build option.&#x20;

   <figure><img src="https://content.gitbook.com/content/C4pLAW1WW2c9V2Kogh1z/blobs/UA3v0llvXYvWJqnvoTzh/troubleshooting-1.20b9f76e01fde8dfc365.png" alt=""><figcaption></figcaption></figure>
4. If you have multiple camera’s on the scene make sure the camera which is looking toward the ad unit has the highest priority depth value.&#x20;

   <figure><img src="https://content.gitbook.com/content/C4pLAW1WW2c9V2Kogh1z/blobs/a1EYBD81hHPceh8TLcL9/troubleshooting-2.b59384c8cc7c6ab8674a.png" alt=""><figcaption></figcaption></figure>
5. Make sure the Unity Event system component is present in the scene.

### Impression but No Click <a href="#id-87812b65-8d1a-4fe4-adb0-06debb085501" id="id-87812b65-8d1a-4fe4-adb0-06debb085501"></a>

1. Make sure there is no collider between the main camera and the ad Unit.
2. Make sure the Unity Event system component is present in the scene.
3. The screen space native ad is not placed inside a Canvas with Overlay render mode

### Memory Management <a href="#id-87812b65-8d1a-4fe4-adb0-06debb085501" id="id-87812b65-8d1a-4fe4-adb0-06debb085501"></a>

* The downloaded ad textures build up in memory and may need manual handling in certain cases.&#x20;
* The accumulated textures are cleared when a scene change or reload happens. However, in the following cases, you should manually manage texture memory
  * Single scene setup
  * Long-running gameplay scene
  * Gameplay Restart/ Progression happens without any scene reload or change
* Destroying texture assets is an expensive operation. The SDK avoids doing so during gameplay as what would be a good time for the SDK could be bad timing for the game and lead to a framerate drop at a critical point
* You can manually invoke Resource.UnloadUnusedAssets() at a strategic point when the gameplay is not demanding to free up the texture memory
* If you don't want to use Unity's UnloadUnusedAssets API,  you can handle the textures at the level of each NativeAdHolder.
* Here is a script that can be used as is or modified to suit your needs

```csharp

using UnityEngine;
using GoogleMobileAds.Api;
using PubScale.SdkOne.NativeAds;
using PubScale.SdkOne;

public class NativeTextureReferences : MonoBehaviour
{

    [SerializeField] NativeAdHolder nativeAdHolder;

    Texture2D prevLoadedAdIconTex = null;
    Texture2D prevLoadedBigImgTex = null;
    Texture2D prevLoadedAdChoicesTex = null;

    NativeAdDisplayHandler curDisplayHandler;


    void Start()
    {
        if (nativeAdHolder != null)
        {
            ClearDummyAdSprites(nativeAdHolder);

            nativeAdHolder.Event_AdRequest += OnNewNativeAdRequested;
            nativeAdHolder.Event_AdLoaded += OnNativeAdLoaded;
        }
        else
            Debug.LogWarning("PubScaleSDK: Please assign a nativeAdHolder in NativeTextureReferences");

    }

    private void OnNewNativeAdRequested()
    {
        if (nativeAdHolder != null && nativeAdHolder.adDisplay != null)
        {
            curDisplayHandler = nativeAdHolder.adDisplay;

            if (curDisplayHandler != null)
            {
                // Ad Icon
                if (curDisplayHandler.adIconImg != null && curDisplayHandler.adIconImg.sprite != null)
                {
                    if (curDisplayHandler.adIconImg.sprite.texture != null)
                        prevLoadedAdIconTex = curDisplayHandler.adIconImg.sprite.texture;
                }

                // Big Image
                if (curDisplayHandler.imageTextures != null && curDisplayHandler.imageTextures.sprite != null)
                {
                    if (curDisplayHandler.imageTextures.sprite.texture != null)
                        prevLoadedBigImgTex = curDisplayHandler.imageTextures.sprite.texture;
                }

                // Ad Choices
                if (curDisplayHandler.adChoicesImg != null && curDisplayHandler.adChoicesImg.sprite != null)
                {
                    if (curDisplayHandler.adChoicesImg.sprite.texture != null)
                        prevLoadedAdChoicesTex = curDisplayHandler.adChoicesImg.sprite.texture;
                }

            }
        }
    }

    private void OnNativeAdLoaded(object arg1, NativeAdEventArgs args)
    {
        if (prevLoadedAdIconTex != null)
        {
            Texture2D tempIconTex = prevLoadedAdIconTex;
            prevLoadedAdIconTex = null;
            Destroy(tempIconTex);   // You can destroy or add to list and Destroy in batch at a convenient point in gameplay
        }

        if (prevLoadedBigImgTex != null)
        {
            Texture2D tempBigImgTex = prevLoadedBigImgTex;
            prevLoadedBigImgTex = null;
            Destroy(tempBigImgTex);  // You can destroy or add to list and Destroy in batch at a convenient point in gameplay
        }

        if (prevLoadedAdChoicesTex != null)
        {
            Texture2D tempAdChoicesTex = prevLoadedAdChoicesTex;
            prevLoadedAdChoicesTex = null;
            Destroy(tempAdChoicesTex); // same as above
        }
    }



    void ClearDummyAdSprites(NativeAdHolder natAdHolder)
    {
        curDisplayHandler = nativeAdHolder.adDisplay;

        RemoveDefaultTextureReferences(curDisplayHandler);

        if (natAdHolder.UseExtraFormats)
        {
            if (natAdHolder.landscapeAdFormats != null && natAdHolder.landscapeAdFormats.Length > 0)
            {
                foreach (NativeAdDisplayHandler displayHandler in natAdHolder.landscapeAdFormats)
                    RemoveDefaultTextureReferences(displayHandler);
            }

            if (natAdHolder.potraitAdFormats != null && natAdHolder.potraitAdFormats.Length > 0)
            {
                foreach (NativeAdDisplayHandler displayHandler in natAdHolder.potraitAdFormats)
                    RemoveDefaultTextureReferences(displayHandler);
            }

            if (natAdHolder.nonMediaType != null && natAdHolder.nonMediaType.Length > 0)
            {
                foreach (NativeAdDisplayHandler displayHandler in natAdHolder.nonMediaType)
                    RemoveDefaultTextureReferences(displayHandler);
            }
        }
    }

    void RemoveDefaultTextureReferences(NativeAdDisplayHandler curDisplayHanlder)
    {
        // Dummy Ad Logo Image
        if (curDisplayHanlder.adIconImg != null)
            ClearImageSprite(curDisplayHanlder.adIconImg);

        // Dummy Big Image
        if (curDisplayHanlder.imageTextures != null)
            ClearImageSprite(curDisplayHanlder.imageTextures);

        // Dummy Ad Choices Icon image
        if (curDisplayHanlder.adChoicesImg != null)
            ClearImageSprite(curDisplayHanlder.adChoicesImg);
    }

    void ClearImageSprite(UnityEngine.UI.Image img)
    {
        if (img != null && img.sprite != null)
            img.sprite = null;
    }

}

```

### *<mark style="color:green;">**What if the display template does not use the icon or big image?**</mark>*

<div align="left"><figure><img src="https://content.gitbook.com/content/C4pLAW1WW2c9V2Kogh1z/blobs/FQseNUqNFa5oLsxeYmPh/Screenshot%202024-06-07%20at%202.19.55%E2%80%AFPM.png" alt="" width="296"><figcaption><p>Does not use Big Image. Displays only the ad icon. </p></figcaption></figure> <figure><img src="https://content.gitbook.com/content/C4pLAW1WW2c9V2Kogh1z/blobs/8GurGWxJRpBPG1Lgqns8/Screenshot%202024-06-07%20at%202.19.55%E2%80%AFPM%20copy.png" alt="" width="306"><figcaption><p>Does not use Ad Icon. Displays only the Big Image.</p></figcaption></figure></div>

* For display templates that show a subset of the ad media:
  * Do not delete the unused media game object and keep its reference and settings in the DisplayHandler script as it is. No change is required.
  * Uncheck it's Image component (but let it remain on the game object)
  * Make adjustments to ensure it does not overlap any displayed ad elements&#x20;
* When the ad loads, the ad icon and big media are loaded into memory (even if not shown). As in the script above you can get the reference to the texture and destroy at a convenient point in the game flow when the intensity is low.
