• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jep7 · Sep 03, 2015 at 05:06 AM · unity ads

Unity Ads Some Users Cannot watch videos sometimes

Hello Community,

I have a problem regarding Unity Video Ads: I have implemented video ads in my android game and first, everything was working fine. Now, some friends are testing it and they sometimes get the problem, that they cannot watch more videos although they have a perfect internet connection. They did not have this fault directly after installing, and also they were able to watch videos again after some day or so. I have checked the code and found out, that (probably) this lines are responible for the difference (ads are working/are not working):

while (!Advertisement.isReady (zone)) { yield return null; }

Advertisement.Show (zone, options);

In the case, where the ad cannot be watched, 'Advertisement.isReady(zone)' always returns false, so the loop is never finished. But I don't know, why sometimes the ad is ready (so I can show it) and sometimes not. I really need to fix this problem, it would be really great, if anyone could help... Thanks,

jep7

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jep7 · Sep 05, 2015 at 10:57 AM 0
Share

@unity-nikkolai , I know, that you are a expert in unity ads themes, so mabye you can help? I thought about the problem and was wondering about the method Advertisement.Initialize(). On https://unityads.unity3d.com/help/Documentation%20for%20Publishers/Integration-Guide-for-Unity-Asset-Store it sais that 'You can initialize the framework only once', but when Initialisation failed (e. g. no network connection) I have to call ' Advertisement.Initialize()' again, haven't I? So I thought, that the problem could be, that the advertisement framework is not initialized sometimes and that is why Advertisement.isReady() returns false. But I also got the problem that videos are not playing any more after some video clips were playing fine? I really don't know the reason, mabye you have an idea how to fix the problem?

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Scribe · Sep 05, 2015 at 11:22 AM

you may want to ask in the forum ads section if this doesn't help, I do not think nikkolai is active on Answers.

This code is untested I am afraid, however the idea behind it is that if the a connection isn't made in x amount of time, we restart the initialize. Maybe the is broken logic, as we don't know for sure how long the connection should take for everyone, but it's something!

 void Awake() {
     if (Advertisement.isSupported) {
         StartCoroutine(AdConnect(<GAMEID>, zone, 10f, 5));
         //I chose 10 seconds to retry after, this is arbitrary
         //you should base this on what you find to be the average time needed to connect (plus some buffer amount, like multiply the average time by 2)
     } else {
         Debug.Log("Platform not supported");
     }
 }
 
 void AdConnect(int ID, string zone = null, float timeOut, int cutoff){
     Advertisement.Initialize (<YOUR GAME ID HERE>);
 
     float startTime;
     for(int i = 0; i < cutoff; i++){
         startTime = Time.realtimeSinceStartup;
 
         while(!Advertisement.IsReady(zone)){
             yield return null;
 
             if(Time.realtimeSinceStartup - startTime >= timeOut) break;
         }
 
         if(Advertisement.IsReady(zone)){
             IsReadyCallback();
             return true;
         }
     }
 
     FailedCallback(cutoff);
 }
 
 void IsReadyCallback(){
     Debug.Log("ready!");
     //start advertising somewhere
 }
 
 void FailedCallback(int c){
     Debug.Log("failed to connect in "+ c +" tries");
     //try again with a larger connection time?
 }


Maybe that is useful, though it sounds like it is not the easiest thing to test if it only happens after a while (strange) and occasionally :S

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jep7 · Sep 05, 2015 at 02:31 PM 0
Share

Thanks for your answer! I can't see directly a thing that I have forgotten in my application after reading your example script, but I got the idea, that the problem could be in the Advertisement.Initialize() call: I always check internet availability in my application and if it is available for the first time, i call Advertisement.Initialize(...). Do you know, what exactly this call does? I mean, could it be possible, that you have to initialize again, e g after loosing internet connection or $$anonymous$$imizing the app for some hours? Answer would be great, mabye I think totally in the wrong direction, but I can also give you more detailed information about my scripts, if necessary

By the way: I learned Time.realtimeSinceStartup from your script. It helps me a lot, until now I have used OnApplicationFocus() and a own server (not just for this) to get the 'real time since startup'. Thank you!

avatar image Scribe · Sep 05, 2015 at 02:54 PM 0
Share

I don't know the internal workings I'm afraid, I have found something that may be of use, before trying to load an advert you could check:

Advertisement.isInitialized as well as isReady, if it is not initialized (`isInitialized == false`), then rerun your initialize code. I would guess loosing internet connection would require you to re-initialize.

$$anonymous$$y guess is, you initialize -> wait until isReady is true -> show an add.

but what happens is:

you initialize -> do some stuff -> loose connection -> you check if isReady -> it returns false and you never reinitialize -> it remains false -> no ads are shown until the app is force to close and reopened or the device restarted.

avatar image
0

Answer by RandomCharacters · Nov 21, 2015 at 07:08 PM

I have the same problem. Ads display in the unity editor but in android sometimes just do not work. This sucks cause I switched over to unity ads. Players watch ads to get coins and now they can't get any coins.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by pablodarde · Jul 01, 2018 at 11:47 PM

I was facing some problems with the time Ads takes to load. I made some changes in the @Scribe 's code. Now, If Ads takes too long time to load, I cancel the load and redirect the user to the main Scene. Please, let me know if someone has a better solution.

That's the code.

 private void Awake()
     {
         if (Advertisement.isSupported)
         {
             StartCoroutine(AdConnect(gameID, "video", 10f, 5));
             //I chose 10 seconds to retry after, this is arbitrary
             //you should base this on what you find to be the average time needed to connect (plus some buffer amount, like multiply the average time by 2)
         }
         else
         {
             Debug.Log("Platform not supported");
         }
     }
 
     public void Start()
     {
         textWait.text = locale.Text.wait;
     }
 
     IEnumerator AdConnect(string ID, string zone, float timeOut, int cutoff)
     {
         Advertisement.Initialize(ID);
 
         float startTime;
         for (int i = 0; i < cutoff; i++)
         {
             startTime = Time.realtimeSinceStartup;
 
             while (!Advertisement.IsReady(zone))
             {
                 yield return null;
 
                 if (Time.realtimeSinceStartup - startTime >= timeOut)
                 {
                     break;
                 }
             }
             
             if (Advertisement.IsReady(zone))
             {
                 IsReadyCallback();
                 yield return true;
             } else
             {
                 FailedCallback(cutoff);
                 break;
             }
         }
 
     }
 
     void IsReadyCallback()
     {
         Debug.Log("ready!");
         ShowOptions options = new ShowOptions();
         options.resultCallback = HandleShowResult;
 
         Advertisement.Show("video", options);
     }
 
     void FailedCallback(int c)
     {
         Debug.Log("failed to connect in " + c + " tries");
         //try again with a larger connection time?
         SceneManager.LoadScene("Main");
     }
 
     private void HandleShowResult(ShowResult result)
     {
         // SceneManager.LoadScene("Main");
         switch (result)
         {
             case ShowResult.Finished:
                 SceneManager.LoadScene("Main");
                 // Debug.Log("The ad was successfully shown.");
                 //
                 // YOUR CODE TO REWARD THE GAMER
                 // Give coins etc.
                 break;
             case ShowResult.Skipped:
                 SceneManager.LoadScene("Main");
                 // Debug.Log("The ad was skipped before reaching the end.");
                 break;
             case ShowResult.Failed:
                 SceneManager.LoadScene("Main");
                 // Debug.LogError("The ad failed to be shown.");
                 break;
         }
     }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

iOS build error with Unity Ads 1 Answer

How can i show ads and then load level in this code 0 Answers

Help displaying ads 0 Answers

Gradle failed to fetch dependencies unity 2018.1.3f1. 0 Answers

Unity Ads Banner not working. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges