Just updated to Unity Ads 3.4.1. Glad to see the canvas overlay issue is fixed, but…
None of events defined in IUnityAdsListener would be fired at least when tested in editor.
This issue totally blocked the process.
Same here, 3.3.0 works fine regarding callbacks
Getting the same error. I honestly don’t understand how such a bug gets released.
I guess they have neither a QA nor a project manager in their team.
@jinming_cao , @robertsze , @luispedrofonseca
Thanks for reporting this issue. We’ll need some more information:
Which version of Unity are you using?
Can you provide the script you are using to test the callbacks?
Can you provide the manifest.json file in your Packages folder?
@ap-unity I’m using the latest Unity version (2019.3.0f3)
This the code I used to handle the ads (hasn’t changed from the previous version):
using System;
using UnityEngine;
using UnityEngine.Advertisements;
using Zenject;
public class AdsManager : IInitializable, IUnityAdsListener
{
public Action<string> OnAdAvailable;
public Action<ShowResult> OnAdCompleted;
public static bool IsAdAvailable => Advertisement.IsReady(ConfigAsset.config.AdPlacementID);
public static bool IsRewardedAdAvailable => Advertisement.IsReady(ConfigAsset.config.RewardedAdPlacementID);
public void Initialize()
{
#if UNITY_IOS
Advertisement.Initialize(ConfigAsset.config.AppleGameID, ConfigAsset.config.AdsTestMode);
#elif UNITY_ANDROID
Advertisement.Initialize (ConfigAsset.config.AndroidGameID, ConfigAsset.config.AdsTestMode);
#else
Debug.LogWarning("AdsManager: No ads on this platform - " + Application.platform);
#endif
Advertisement.AddListener(this);
}
public void ShowAd()
{
Advertisement.Show();
}
public void ShowRewardedAd()
{
Advertisement.Show (ConfigAsset.config.RewardedAdPlacementID);
}
public void OnUnityAdsReady(string placementId)
{
OnAdAvailable?.Invoke(placementId);
}
public void OnUnityAdsDidError(string message)
{
Debug.LogError(message);
}
public void OnUnityAdsDidStart(string placementId)
{
Debug.Log($"Ad started: {placementId}");
}
public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
{
OnAdCompleted?.Invoke(showResult);
}
}
And this is my manifest.json file:
{
"dependencies": {
"com.unity.2d.animation": "3.0.8",
"com.unity.2d.sprite": "1.0.0",
"com.unity.ads": "3.4.1",
"com.unity.analytics": "3.3.4",
"com.unity.device-simulator": "2.0.0-preview",
"com.unity.ide.rider": "1.1.4",
"com.unity.quicksearch": "1.4.1",
"com.unity.render-pipelines.core": "7.1.6",
"com.unity.render-pipelines.universal": "7.1.6",
"com.unity.shadergraph": "7.1.6",
"com.unity.test-framework": "1.1.8",
"com.unity.textmeshpro": "2.0.1",
"com.unity.timeline": "1.2.9",
"com.unity.ugui": "1.0.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.animation": "1.0.0",
"com.unity.modules.assetbundle": "1.0.0",
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.cloth": "1.0.0",
"com.unity.modules.director": "1.0.0",
"com.unity.modules.imageconversion": "1.0.0",
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.particlesystem": "1.0.0",
"com.unity.modules.physics": "1.0.0",
"com.unity.modules.physics2d": "1.0.0",
"com.unity.modules.screencapture": "1.0.0",
"com.unity.modules.terrain": "1.0.0",
"com.unity.modules.terrainphysics": "1.0.0",
"com.unity.modules.tilemap": "1.0.0",
"com.unity.modules.ui": "1.0.0",
"com.unity.modules.uielements": "1.0.0",
"com.unity.modules.umbra": "1.0.0",
"com.unity.modules.unityanalytics": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.unitywebrequestassetbundle": "1.0.0",
"com.unity.modules.unitywebrequestaudio": "1.0.0",
"com.unity.modules.unitywebrequesttexture": "1.0.0",
"com.unity.modules.unitywebrequestwww": "1.0.0",
"com.unity.modules.vehicles": "1.0.0",
"com.unity.modules.video": "1.0.0",
"com.unity.modules.vr": "1.0.0",
"com.unity.modules.wind": "1.0.0",
"com.unity.modules.xr": "1.0.0"
}
}
So I was able to use your script and was able to get callbacks just fine in the editor. I’ll share the script with you below, but here are some things that I observed.
- Make sure your testing on a proper platform (Android or IOS) in your build settings or your code will just dump a warning that your on an unsupported platform.
- Nowhere in your script are you setting OnAdAvailable or OnAdComplete objects which means while the callbacks are happening from the ads sdk, they may not be calling into your code properly because of this.
- I have no idea what Zenject does exactly, but it seems to be a dependency injection framework??, but it looks like your using it to manage the ads sdk? are you sure that your script is properly being called by zenject? Id try testing this without zenject to ensure your project is working as you expect.
Here is what I modified your code to. Simply attach this to a gameobject and it will show an ad on playmode start, and will essentially spam you with ad after ad after ad each time you close. You can click the close button and see your console spammed with the finish state as well as the ready state for each placement right after. Please let me know if your still having issues.
using System;
using UnityEngine;
using UnityEngine.Advertisements;
public class AdsManager : MonoBehaviour, IUnityAdsListener
{
public Action<string> OnAdAvailable;
public Action<ShowResult> OnAdCompleted;
public static bool IsAdAvailable => Advertisement.IsReady("video");
public static bool IsRewardedAdAvailable => Advertisement.IsReady("rewardedVideo");
public void Start()
{
#if UNITY_IOS
Advertisement.Initialize ("14850", false);
#elif UNITY_ANDROID
Advertisement.Initialize ("14851", false);
#else
Debug.LogWarning("AdsManager: No ads on this platform - " + Application.platform);
#endif
Advertisement.AddListener(this);
}
public void ShowAd()
{
Advertisement.Show();
}
public void ShowRewardedAd()
{
Advertisement.Show ("rewardedVideo");
}
public void OnUnityAdsReady(string placementId)
{
Debug.Log("OnUnityAdsReady: " + placementId);
if (placementId == "rewardedVideo") {
ShowRewardedAd();
}
}
public void OnUnityAdsDidError(string message)
{
Debug.Log("OnUnityAdsDidError: " + message);
}
public void OnUnityAdsDidStart(string placementId)
{
Debug.Log("OnUnityAdsDidStart: " + placementId);
}
public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
{
Debug.Log("OnUnityAdsDidFinish [" + showResult + "]: " + placementId);
}
}
Hi sbankhead,
I’m using 2018.3.8 and I have exactly same issue with luispedrofonseca, please note that both our code works without issue in 3.4.0. The callback is missing only in 3.4.1.
I’m using Android platform in editor, and I can’t receive any events from any API defined in the listener.
@sbankhead Please notice that my code didn’t change from 3.4.0 to 3.4.1!
Also, not sure what you mean with:
@jinming_cao , @luispedrofonseca
We are still having trouble reproducing this issue. Would you be able to open a support:
unityads-support@unity3d.com
I’ll when I get some time today.
BTW, this issue exists only with Advertisement API in 3.4.1
Monetization API in 3.4.0 and 3.4.1 and Adv API in 3.4.0 works just fine regarding event callbacks.
All cases tested with identical code. (I use a boolean to select which API should be used)
I guess he meant that the issue is caused by missing the assignment to the two Action variables. But I believe these two public members are assigned outside AdManager class. Am I right? They are apparently not the cause of this issue.
For the record I’m not seeing the described problem in Unity 2017.4.35f1. I have not tested it with other Unity versions.
Hi Everyone ( @AdXxRi123 @jinming_cao @luispedrofonseca ),
Today, I think I finally solved an issue I had with IUnityAdsListener callbacks not occurring in specific conditions. I’m not sure if this will help anyone, but may provide some insight, so I’ll share my experience in trying to figure out Unity Ads.
My fix seems to have been upgrading my project from Unity 2019.1.8f1 to 2019.2.19f1 (and then turning on/off some lightbulb icon in the Scene view), using Unity Hub.
The problem I had in 2019.1.8f1 only occurred when I played the game after the first time on Android. The first time playing my game after Build and Run to my Android device, IUnityAdsListener callback functions would work fine as expected (confirmed via logcat debug lines). If I pressed the Back button, however, and touched the icon to restart the (cached/still exists in Recent Apps/swipe list) game from the Android homescreen, the IUnityAdsListener callbacks would NOT happen. (If I swiped the game off the recent apps list, and played it again, it would work fine but only the first time.)
At some point, I added .RemoveListener(this); in an OnDestroy() of my ads script. I can’t remember exactly, but I think this allowed me to get it working correctly if I replayed the level with the Ad in it (i.e., reloaded the scene) during the first time running the game, i.e. correctly get IUnityAdsListener callbacks. But that was all occurring before a Back button press and restarting the game from the homescreen.
I was about to try .RemoveAllListeners btw, but it looks like I don’t need to go that route. I had been using .AddListener very early in the script, but discovered that, in the problem cases (i.e. non-first fresh runs), Advertiser.listeners already existed. Also, in both working and problem cases, the Ads themselves were already cached or stored from the last time, i.e. .IsReady worked and was true, so basically I would SEE the ads get shown, just not know when they finished in the problem cases. (it seems like the ads got readied from the last time, very soon after Advertisement.Show() was called, and that would survive through restarting the game from homescreen.)
I had been using Unity Ads 3.4.1 and still use it now. In the older install (Unity 2019.1.8f1), I used the Package Manager to downgrade to various other Unity Ads versions mentioned in these threads like 3.4.0, 3.3.1 I think, and 2.0.8 but none solved the problem so I stayed with 3.4.1. I did turn off the extra option in Services “Enable built-in Ads extension” under Advanced, but I don’t think that had much effect actually. I was worried about potential conflicting installs of the libraries/package, and I can’t even remember how I first obtained Unity Ads, whether via the Asset Store or Package Manager, just that I deleted some files/contents after getting it ( @Kaymax knows the process isn’t exactly clear), and it worked mostly, except for my problem. I think I have 3.4.1, but who knows exactly, cause sometimes .version tells me 3.4.0, but I read somewhere .version isn’t always accurate (does Charles know, who is Charles, something about a method to confirm-- but I didn’t do the Charles thing, in any case, to get it working as, well, you know. advertised).
Related threads on IUnityAdsListener callbacks not happening as expected: