Search code examples
unity-game-engineinitializationads

Why is Unity Ads 'Advertisement.Initialize()' making my game lag?


When my game starts the welcome screen has quite a few animations that play out. It was working fine until I implemented Unity Ads into my game. Now there is a noticeable lag when this bit of code executes:

Advertisement.Initialize ();.

It only lasts for a second but it is quite nasty. I tried putting the code in a co-routine and calling after the bulk of the heavy animations are completed but it still causes a considerable disruption to the remaining simple animations that are looping.

I'm thinking about putting it inside of my "Earn Button" onClick event but then the user will have to wait for the ads to load up which can take up to 5 seconds in my experience.

Is there a way I can call this code while the splash screen is loading?

I am testing on a Samsung S5 if that helps.


Solution

  • I think it takes long because it will download video Ads and try to cache them into the device. It will take even longer for devices with slow internet.

    I assume you tried to use AsyncTask Here , if not, give it a go and Initialize UnityAds on a separate thread and see if it helps.

    Another way is to call Initialize() and then check if the Video Ad is ready and put a loading screen while its downloading all the video Ads.

    something like

     While(! Advertisement.isready())    
     {    
        // loading..  
     }
    

    I am not sure if it downloads videos every time you open the app or once every sometime, you need to ask UnityAds for that.

    you get the idea.. hope this helps