Search Unity

Admob lagging my game - cannot fix

Discussion in 'Scripting' started by squigglyo, Jan 16, 2017.

  1. squigglyo

    squigglyo

    Joined:
    May 21, 2012
    Posts:
    107
    Hey guys

    Im using the Google Admobs SDK and have gotten Banners working, but have found that even the slightest animation in them causes my game to loose a third of its FPS.

    Finding no way around this, ive opted to just show ads during the 'death' screens. However, this still lags the game. Even after the ad is Hidden or even Destroyed, there is a drop of about 5-10 FPS.

    Below is the code im using.

    When the player crashes, the BannerAd function is called, and when they click the Retry button in the game, it reloads the level and calls the DestroyBannerAd function.

    Ive tried just hiding the ad and this does the same. If I leave the ad on the screen for 5 min or so, the phone gets really hot, the fps drops from 30 to about 20, and then stays there when I Hide or Destroy the ad.


    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using GoogleMobileAds.Api;
    4.  
    5. public class AdTest : MonoBehaviour {
    6.     const string android_fullscreen_all = "myFullscreen";
    7.     const string android_bannerad = "myBanner";
    8.  
    9.     InterstitialAd interstitial;
    10.     BannerView bannerView;
    11.  
    12.     void Start ()
    13.     {
    14.     }
    15.  
    16.  
    17.     public void BannerAd()
    18.     {
    19.         #if UNITY_EDITOR
    20.         string adUnitId = "unused";
    21.         #elif UNITY_ANDROID
    22.         string adUnitId = android_bannerad;
    23.         #else
    24.         string adUnitId = "unexpected_platform";
    25.         #endif
    26.  
    27.         if (bannerView != null) {
    28.             bannerView.Destroy ();
    29.         }
    30.  
    31.         AdSize adSize = AdSize.SmartBanner;
    32.         //AdSize adSize = new AdSize (480, 32); //Small with images
    33.         //AdSize adSize = new AdSize(320, 50); //small, text
    34.  
    35.         bannerView = new BannerView(adUnitId, adSize , AdPosition.Bottom);
    36.         // Create an empty ad request.
    37.         AdRequest request = new AdRequest.Builder().Build();
    38.  
    39.         // Load the banner with the request.
    40.         bannerView.LoadAd(request);
    41.  
    42.     }
    43.  
    44.     public void ShowBannerAd()
    45.     {
    46.         if (bannerView != null) {
    47.  
    48.             bannerView.Show ();
    49.         }
    50.  
    51.     }
    52.  
    53.     public void HideBannerAd()
    54.     {
    55.         if (bannerView != null) {
    56.             bannerView.Hide ();
    57.         }
    58.     }
    59.  
    60.  
    61.     public void DestroyBannerAd()
    62.     {
    63.         if (bannerView != null) {
    64.             HideBannerAd ();      
    65.             bannerView.Destroy ();
    66.         }
    67.     }
    68.  
    69. }
    70.  
     
  2. alissonvegea

    alissonvegea

    Joined:
    Oct 8, 2020
    Posts:
    1
    Same problem here. Only when animating.