Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

10-Step Integration Guide for Unity Ads in Unity

Discussion in 'Unity Ads & User Acquisition' started by unity-nikkolai, Jan 29, 2015.

  1. jpv1234

    jpv1234

    Joined:
    Dec 5, 2014
    Posts:
    89
    Thank you very much Nikkolai, I removed the Unity Ads assets and the error disappeared. However the service was not turning on, it remained disabled. If someone is having this problem, you just have to restart Unity and everything will work fine
     
  2. Databases

    Databases

    Joined:
    Mar 24, 2014
    Posts:
    22
    Cannot Change Game ID, when i restart unity after adding my own Game ID and disabling test mode, it show the previous Game ID and the test mode is enabled, so nothing is saved...any idea?
     
  3. mollavdev

    mollavdev

    Joined:
    Sep 6, 2015
    Posts:
    2
    Hello!
    Before 5.2 Unity Ads showed fine. After that I decided to use new Unity Services feature. So I turned it on and added the code to object in root. In logs in xcode I can see "Unity Ads initialized with 3 campaigns and 2 zones". Test ads don't show on iOS, Android, Unity Editor Player. Advertisement.IsReady("rewardedVideo")) returns false.
    Please help me with this issue. What am I doing wrong? Code and screenshots are bellow.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Advertisements;
    3.  
    4. public class UnityVideoAds : MonoBehaviour
    5. {
    6.     public void ShowRewardedAd()
    7.     {
    8.         if (Advertisement.IsReady("rewardedVideo"))
    9.         {
    10.             var options = new ShowOptions { resultCallback = HandleShowResult };
    11.             Advertisement.Show("rewardedVideo", options);
    12.         }
    13.     }
    14.  
    15.     private void HandleShowResult(ShowResult result)
    16.     {
    17.         switch (result)
    18.         {
    19.         case ShowResult.Finished:
    20.             Debug.Log("The ad was successfully shown.");
    21.             //
    22.             // YOUR CODE TO REWARD THE GAMER
    23.             // Give coins etc.
    24.             break;
    25.         case ShowResult.Skipped:
    26.             Debug.Log("The ad was skipped before reaching the end.");
    27.             break;
    28.         case ShowResult.Failed:
    29.             Debug.LogError("The ad failed to be shown.");
    30.             break;
    31.         }
    32.     }
    33.  
    34.     void Start() {
    35.         ShowRewardedAd ();
    36.     }
    37. }
    Снимок экрана 2015-09-14 в 17.14.10.png

    Снимок экрана 2015-09-14 в 17.14.37.png
     
    Last edited: Sep 14, 2015
  4. MadMapp

    MadMapp

    Joined:
    Nov 15, 2012
    Posts:
    49
    wow, why did unity break the adverts in 5.2?? none of the example code works if(Advertisement.isReady()){ Advertisement.Show(); } returns the error
    Assets/unityAds.cs(9,13): error CS0433: The imported type `UnityEngine.Advertisements.Advertisement' is defined multiple times
    and same issue as above with the rewarded adverts, is there already a solution to this that i have missed?
     
  5. Salazar

    Salazar

    Joined:
    Sep 2, 2013
    Posts:
    235
    Hello @rizla
    You should use the code samples given with unity 5.2. You may want take a look to this thread. Because some API changes made.

    Regards,
     
    MadMapp likes this.
  6. MadMapp

    MadMapp

    Joined:
    Nov 15, 2012
    Posts:
    49
    @Salazar thanks mate, i found the problems, lots of minor changes lead to a very confused and disgruntled me, my main issue i think was having the unity ads asset downloaded from the store imported in to my project, removed that and the exampled scripts in the service window worked fine
     
    Salazar likes this.
  7. unity-nikkolai

    unity-nikkolai

    Joined:
    Sep 18, 2014
    Posts:
    540
    @mollavdev: That script won't work in most if not all cases. Unless Unity Ads is already initialized and ready to show when the the GameObject that script is attached to is instantiated, ads will not be shown.

    If you want to show ads on Start(), use yield statements to check periodically if ads are ready before showing. There's an example script for ShowAdsOnLoad in the Unity Ads Helper project that does this.

    @rizla: Because Unity Ads is included with Unity 5.2 when you have Ads enabled in the Services window, you will need to remove the existing Unity Ads package assets from your project. Having both the Unity Ads asset package imported in your project and having Ads enabled in the Services window will throw an error.
     
    DBarlok, mollavdev and Salazar like this.
  8. MadMapp

    MadMapp

    Joined:
    Nov 15, 2012
    Posts:
    49
    @unity-nikkolai cheers nikkolai, i have found and worked out the intergration, perhaps a video should be posted somewhere showing the changes, and set up, i agree its much easier now, just completely different to how we used to do it. whats the story with all the dash boards, will they become 1, will the older games with the old ids need updateing or will continue to run fine?
     
    FranticThumbs likes this.
  9. Kai_Zu

    Kai_Zu

    Joined:
    Dec 14, 2013
    Posts:
    17
    Hi,

    Building an iOS-version of my app fails reliably in XCode with error message:

    UnityAds.bundle: No such file or directory

    If I dig up that file and put it where it's supposed to be (I know, I know, not a smart move :) the error I get is:

    UnityAds.h file not found

    That file is not present on my mac.

    BTW: I removed all traces of the old UnityAds-framework from my project as instructed when the ad-thingy became a service.

    XCode version is: Version 7.0 (7A220)
    Unity version is: 5.2.0f3 (Personal)

    Anyone has any hacks, ideas or workarounds?

    Thanks to everyone already in advance
     
  10. unity-nikkolai

    unity-nikkolai

    Joined:
    Sep 18, 2014
    Posts:
    540
    Unity Ads is currently undergoing a data model migration in order to more fully support the Unity Developer Network and its organization/project model. At the moment, the features available through the new Admin are somewhat limited. Over the next several weeks, we will be adding features back into Unity Ads Admin, beginning with features for monetizing with Unity Ads.

    Existing games will continue to work without any need to update them. All games will eventually be migrated to the new Admin, after which the old Admin will be deprecated. This is a lengthy and involved process, so it may take a while before things come together again under a single admin. You should start see the new Admin begin to take shape over the next couple weeks though. Let me know if you have any questions about it.
     
    DBarlok and Salazar like this.
  11. Kai_Zu

    Kai_Zu

    Joined:
    Dec 14, 2013
    Posts:
    17
    No help like self-help. I succeeded in getting the ads to work. If anyone else has this same problem what helped for me was that I downloaded the Unity Ads SDK from the corresponding site and copied missing files from it into the XCode-project whenever it complained about missing files. Running the app on an iPad2 worked fine - the test ad was displayed as it should be.
     
  12. unity-nikkolai

    unity-nikkolai

    Joined:
    Sep 18, 2014
    Posts:
    540
  13. ArtisV

    ArtisV

    Joined:
    Jun 25, 2013
    Posts:
    9
    Hello!

    I have a question regarding rewarded ad integration. I use of course the newest unity version 5.2.2.
    I use the same reward ad code example which is provided in unity -> services. I place that code in my games main menu. So when I start game first scene is main menu, the ads is initialized there. So this means that loading other scenes (levels), keeps the ads initialized and ad system in the background is doing its thing - downloading new ads in device... ? When player dies then the scene is switched to Main Menu scene and is asked to watch an ad for a another batch of lives. (I had a feeling that sometimes test ad cant be shown. I thought maybe its because system just now loaded scene with ad script at the same moment did initialize ads, and didnt had time to download ad)
    Is this good enough implementation or I need to initialize ad system in same scene where the show ad will be called after some time?
     
  14. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    could someone please link me to a documentation that explains how pay is actually delivered once the amount of impressions is high enough to warent the payment to the developer? Thanks! just not sure how that works, how often its sent out where i can set up the information so it sends the payment to the correct bank etc. thanks!
     
  15. KhmerDude

    KhmerDude

    Joined:
    Oct 18, 2012
    Posts:
    105
    hi so i have done everything you mention it and the ads work but how would i get it to work only when the user click the restart button?
     
  16. basil

    basil

    Joined:
    Dec 13, 2012
    Posts:
    9
    Hi,

    I encounter problem on merging manifest.

    Error: [Temp/StagingArea/AndroidManifest-main.xml:3, /Users/panfilomarianojr/UnityDev/ToysInc/src/Unity/Temp/StagingArea/android-libraries/MoPub_lib/AndroidManifest.xml:29] Trying to merge incompatible /manifest/uses-permission[@name=android.permission.WRITE_EXTERNAL_STORAGE] element:

    Error: [Temp/StagingArea/AndroidManifest-main.xml, /Users/panfilomarianojr/UnityDev/ToysInc/src/Unity/Temp/StagingArea/android-libraries/unityads-release/AndroidManifest.xml:7] Trying to merge incompatible /manifest/application/activity[@name=com.unity3d.ads.android.view.UnityAdsFullscreenActivity] element:


    Im am using Unity3d 5.2.3f1

    Since i removed the UnityAds package from Asset Store, I cant edit the manifest anymore as suggested in previous conversation.

    Can anyone help me. am i missing something,

    Thanks
     
  17. basil

    basil

    Joined:
    Dec 13, 2012
    Posts:
    9

    I fixed by using the package from Asset Store and removing


    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application>
    <activity
    android:name="com.unity3d.ads.android.view.UnityAdsFullscreenActivity"
    android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    android:hardwareAccelerated="true"
    tools:ignore="UnusedAttribute"/>
    </application>

    in the AndroidManifest.xml

    Im not sure if it will affect anything in the game ads but anyway it fixed the current problem.
     
  18. MadDevil

    MadDevil

    Joined:
    Nov 4, 2014
    Posts:
    4
    Hey guys, I am working on unity 4.6.6 and I am trying to add unity ads to my game but I am unable to make an build because of manifest merge errors

    1)

    I am getting the following error while I am build the APK

    Error: [Temp\StagingArea\AndroidManifest-main.xml, C:\Users\Murtaza\Desktop\HOMEWORK\_Cricket\Temp\StagingArea\android-libraries\unityads\AndroidManifest.xml:7] Trying to merge incompatible /manifest/application/activity[@name=com.unity3d.ads.android.view.UnityAdsFullscreenActivity] element:

    UnityEditor.HostView:OnGUI()




    2)


    Error building Player: CommandInvokationFailure: Unable to merge android manifests. See the Console for more details.
    C:/Program Files/Java/jdk1.7.0_51\bin\java.exe -Xmx2048M -Dcom.android.sdkmanager.toolsdir="D:/Android/android-sdk\tools" -Dfile.encoding=UTF8 -jar "C:/Program Files (x86)/Unity/Editor/Data/BuildTargetTools/AndroidPlayer\sdktools.jar" -


    would appreciate any help to solve this.

    Cheers.
     
  19. DeanMarquette

    DeanMarquette

    Joined:
    Feb 10, 2015
    Posts:
    165
    Still no support for Windows??
     
  20. adam_mehman

    adam_mehman

    Joined:
    Dec 11, 2014
    Posts:
    104
    Hi,

    UnityAds are being showed in Editor but not on Device (they got stuck in the LogWhenUnityAdsIsInitialized() Coroutine.

    What should I do to fix it?

    Regards
     
  21. RayJr

    RayJr

    Joined:
    Oct 10, 2014
    Posts:
    3
    Has anyone seen this error? I'm using 5.3.1f1 and I get this as soon as I click on the Unity Ads switch.

    If I create a new Unity project and turn on Ads it works fine. I only get this error if I turn Ads on on my completed game project.
     

    Attached Files:

  22. bricevdm

    bricevdm

    Joined:
    Nov 4, 2009
    Posts:
    34
    Same here: 5.3.1f1
    However, I get the same crash in a new project (when linking to my existing project ID), unlike you RayJr.
    I could not get trough the creation of the Ads project with the web interface either (see screenshot, love those error msgs btw))

    Thanks for the insight though! I was able to generate a new project ID from an empty unity project (inside the editor), rename it trough the editor services panel to the same name (after switching back to my main project and renaming the old ID too) and then use that same organization/project ID again the my main unity project. pfiouu...

    UnityAdsError.png

    "An error occurred while calling external API"
     
    Last edited: Jan 12, 2016
  23. fajarkecoak

    fajarkecoak

    Joined:
    May 17, 2015
    Posts:
    11
    hi, this is the first time i use unity ads.
    and i am forget to change the ads to rewarded video. and i change it on this morning.
    how long it will updated?
    sorry for my bad english
     
  24. Salazar

    Salazar

    Joined:
    Sep 2, 2013
    Posts:
    235
  25. Lucates

    Lucates

    Joined:
    Oct 19, 2015
    Posts:
    8
    How long takes to get Callback link for unity ads from unity support?
     
  26. macchia86

    macchia86

    Joined:
    Jan 20, 2017
    Posts:
    1
    Hello Unity team,
    I have integrated unity in android successfully.
    But it runs continuously, How to stop it.

    Thank You
     
  27. creativeshyam

    creativeshyam

    Joined:
    Apr 8, 2016
    Posts:
    4
    Hi. I am able to see Test ads. But I have a doubt. @ Analytics web page I am able to see 'Integration not complete' If I want earn money from ads, should I complete integration ? or can I leave it? please help me. Tnks in adv.
     

    Attached Files:

  28. IcyBot

    IcyBot

    Joined:
    May 4, 2017
    Posts:
    5
    I've successfully intergrated ads in my app however they obviously show after every time the player has died. If there a way to the set gameobject the scripts are attached to to active only after x amount of deaths?
     
  29. resurrectiondesign

    resurrectiondesign

    Joined:
    Jan 20, 2017
    Posts:
    3
    I am using ShowAdsOnLoad script but :-


    Code (CSharp):
    1.  
    2.  
    3. using UnityEngine;
    4. using System.Collections;
    5.  
    6. public class UnityAdsOnLoad : MonoBehaviour
    7. {
    8.     public string placementId;
    9.  
    10.     public float initTimeout = 15f;  // Time in seconds to allow for init to complete before canceling show.
    11.     public float showTimeout = 15f;  // Time in seconds to allow for ad to be ready before canceling show.
    12.  
    13.     private float _yieldTime = 0.5f; // Time in seconds between evaluation attempts.
    14.     private float _startTime = 0f;
    15.  
    16.     IEnumerator Start ()
    17.     {
    18.         if (!UnityAdsHelper.isSupported) yield break;
    19.         else if (!UnityAdsHelper.isInitialized) UnityAdsHelper.Initialize();
    20.  
    21.         string placementName = string.IsNullOrEmpty(placementId) ? "the default ad placement" : placementId;
    22.  
    23.         _startTime = Time.timeSinceLevelLoad;
    24.  
    25.         while (!UnityAdsHelper.isInitialized)
    26.         {
    27.             if (initTimeout > 0 && Time.timeSinceLevelLoad - _startTime > initTimeout)
    28.             {
    29.                 Debug.LogWarning(string.Format("Unity Ads failed to initialize in a timely manner. " +
    30.                     "An ad for {0} will not be shown on load.",placementName));
    31.                 yield break;
    32.             }
    33.  
    34.             yield return new WaitForSeconds(_yieldTime);
    35.         }
    36.  
    37.         Debug.Log("Unity Ads has finished initializing. Waiting for ads to be ready...");
    38.  
    39.         _startTime = Time.timeSinceLevelLoad;
    40.  
    41.         while (!UnityAdsHelper.IsReady(placementId))
    42.         {
    43.             if (showTimeout > 0 && Time.timeSinceLevelLoad - _startTime > showTimeout)
    44.             {
    45.                 Debug.LogWarning(string.Format("Unity Ads failed to be ready in a timely manner. " +
    46.                     "An ad for {0} will not be shown on load.",placementName));
    47.                 yield break;
    48.             }
    49.  
    50.             yield return new WaitForSeconds(_yieldTime);
    51.         }
    52.  
    53.         Debug.Log(string.Format("Ads for {0} are available and ready.",placementName));
    54.  
    55.         UnityAdsHelper.ShowAd(placementId);
    56.     }
    57.  
    58.     void OnDestroy ()
    59.     {
    60.         StopAllCoroutines();
    61.     }
    62. }
    63.  



    Problem: the scene is loading and showing for few seconds and then ad is starting to show.

    Case 1 : scene to wait till the ad finish showing/skipped/failed.

    case 2: scene to wait till the ad finish showing/skipped/failed, while its the ad is loading it can show a image/text "Loading" (any public gameobject )