- Home /
why is my game lagging when using Unity Ads?
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.
Answer by mtdrume · Feb 17, 2015 at 12:30 PM
I use a second splash screen for my game. It simply waits to be informed that the Ads component has been initialized then loads the level/game. Only issue is that if no active internet, game will never load. But this link: http://answers.unity3d.com/questions/567497/how-to-100-check-internet-availability.html#answer-567499 covers how to check for an internet connection. Hope it helps :)
using UnityEngine;
using UnityEngine.Advertisements;
using System.Collections;
public class DestroyLogo : MonoBehaviour {
void Start ()
{
// initialize adverts
if (Advertisement.isSupported) {
Advertisement.allowPrecache = true;
Advertisement.Initialize ("131625064");
} else {
Debug.Log("Platform not supported");
}
// end initialize
}
void Update()
{
// see if its done.
if (Advertisement.isInitialized)
{
Application.LoadLevel ("level");
}
}
}
It is still feasible that unity ads could fail to initialize for some reason besides internet connection. I'd just come up with a timeout value of maybe 10 seconds that is the max you would wait for it, and then go to the game when that passes.
Add to the top: private float timer = 0f;
In your update:
void Update()
{
timer += Time.deltaTime;
if (Advertisement.isInitialized || timer >= 10.0f)
{
Application.LoadLevel("level");
}
{
@Joe-Censored is this worked with you? if yes, could you show me how you initialized your ads?
thanks you
Your answer
![](https://koobas.hobune.stream/wayback/20220613181624im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
admob reward ad shows after clicking several times (problem) 1 Answer
My unity ads aren't showing "real" ads. 2 Answers
Does Google/Apple/Someone else take a cut off the ad revenue on my products? 0 Answers
How to check if a test ad is ready 0 Answers
Getting error on using Adduplex ads in Windows Phone 0 Answers