Unity version: 2018.4.22
Unity ads version: 3.7.3
Platform: Android
Ads setting : Test Mode Enable
All the code is exactly the same as in example.
Initalizing & Ads load are working properly as it should be. I got the following log from console.
“Unity Ads initialization complete.”
“Loading Ad: Rewarded_Android”
“Ad Loaded: Rewarded_Android”
but after Advertisement.Show had been called, the test ad appears.
but after closing it, OnUnityAdsShowComplete doesn’t trigger.
(I also add Debug.Log at start of the function to check this)
when I call Advertisement.Show again, I got error in console.
“Error showing Ad Unit Rewarded_Android: NOT_READY - Placement Rewarded_Android is not ready”
which means OnUnityAdsFailedToLoad was triggered.
Could you please suggest what I did wrong?
Thanks in advance & best regard
We are experiencing the same issue. Something seems to be wrong with the test ads. OnUnityAdsShowStart works as it’s supposed to but OnUnityAdsShowComplete never triggers. The only difference in our configuration is that our Unity version is 2018.4.36f1 but everything else matches.
I have the exact same problem with my project
Unity version: 2020.3.14f1
Unity ads version: 3.7.3
the problem persist even if I use the old “void HandleShowResult(ShowResult result)” method, not just the new OnUnityAdsShowComplete() if I thy to use in the new suggeste implementation
“void HandleShowResult(ShowResult result)” using no listeners still works
For your problem, I have tested with UnityAds SDK 3.7.5. May I know whether this happened each time? It works well on my side.
Here are some codes you may need to pay attention to: Advertisement.Initialize(androidID, testMode, true); //The last true is for EnablePerPlacement. Without it, you may load ads failed. Advertisement.Show(mySurfacingId2, this); //You need to set up listener to catch the callback.
the problem seems fixed in the builld after re-enabling EnablePerPlacement (not sure why one would turn it off), but it still persist in the editor. It’s a bit annoying because I have to build every time I have some changes I want to verify
i have the same bug. 2020.3.14 and sdk 3.7.5. “OnUnityAdsShowComplete” dont work.
There may be something wrong with the test ads. Instead of a video, it shows a static image. Perhaps because of this, it does not work.
OnUnityAdsShowStart - work
OnUnityAdsDidStart - work
OnUnityAdsDidFinish - work.
I understand your problem. In the editor, there is only a fake ad, and it won’t fire the onComplete callback. If you want to test it, you need to build it as a mobile version and run it on a real device or simulator. It should work.
I also have the same problem on Unity 2020.3.14f1 and SDK 3.7.5, wheter I run it from the editor or my Android device, the OnUnityAdsShowComplete isn’t triggering.
May I check whether you use the “IUnityAdsShowListener” interface and set it to your SDK(Advertisement.Show(placementId, this); )? Only this setting will trigger the “OnUnityAdsShowComplete”. What’s more, it will not be triggered in the Editor, but only on the real phone.
If you still meet this problem, may you send us some sample codes of your project?
Yes of course, thanks a lot LIU. I’m loading the Ad through the ShowAd() method with the continueButton, it’s linked via the Editor in case you require that information.
using UnityEngine;
using UnityEngine.Advertisements;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class RewardedAd : MonoBehaviour, IUnityAdsInitializationListener, IUnityAdsLoadListener, IUnityAdsShowListener
{
#if UNITY_IOS
private string gameId = "4268458";
#elif UNITY_ANDROID
private string gameId = "4268459";
#endif
bool testMode = true;
private string adUnitId;
public GameMaster gm;
public Button continueButton;
void Start()
{
adUnitId = "Rewarded_Android";
Advertisement.Initialize(gameId, testMode, true, this);
}
public void LoadAd()
{
Debug.Log("Loading Ad");
Advertisement.Load(adUnitId, this);
}
public void ShowAd()
{
Debug.Log("Showing Ad");
Advertisement.Show(adUnitId, this);
}
public void OnInitializationComplete()
{
Debug.Log("Unity Ads initialization complete.");
LoadAd();
}
public void OnInitializationFailed(UnityAdsInitializationError error, string message)
{
Debug.Log($"Unity Ads Initialization Failed: {error.ToString()} - {message}");
SceneManager.LoadScene(SceneManager.GetActiveScene().name, LoadSceneMode.Single);
}
// Implement Load Listener and Show Listener interface methods:
public void OnUnityAdsAdLoaded(string adUnitId)
{
Debug.Log("Ad Loaded successfully");
// Optionally execute code if the Ad Unit successfully loads content.
continueButton.interactable = true;
}
public void OnUnityAdsFailedToLoad(string adUnitId, UnityAdsLoadError error, string message)
{
Debug.Log($"Error loading Ad Unit: {adUnitId} - {error.ToString()} - {message}");
// Optionally execute code if the Ad Unit fails to load, such as attempting to try again.
SceneManager.LoadScene(SceneManager.GetActiveScene().name, LoadSceneMode.Single);
}
public void OnUnityAdsShowFailure(string adUnitId, UnityAdsShowError error, string message)
{
Debug.Log($"Error showing Ad Unit {adUnitId}: {error.ToString()} - {message}");
// Optionally execite code if the Ad Unit fails to show, such as loading another ad.
SceneManager.LoadScene(SceneManager.GetActiveScene().name, LoadSceneMode.Single);
}
public void OnUnityAdsShowStart(string adUnitId) {
Debug.Log("OnUnityAdsShowStart");
}
public void OnUnityAdsShowClick(string adUnitId) {
Debug.Log("OnUnityAdsShowClick");
}
public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState) {
Debug.Log("OnUnityAdsShowComplete");
//gm.HideContinueScreen();
//continueButton.GetComponentInChildren<Text>().text = "LET'S GO";
if (adUnitId.Equals("Rewarded_Android") && showCompletionState == UnityAdsShowCompletionState.COMPLETED)
{
Debug.Log("Completed Rewarded Ad");
}
Advertisement.Load(adUnitId);
}
private void OnDestroy()
{
}
}
Hello everyone, I am following the latest implementation and I am having the same problem “Fake” ad like @LIU_Hanyang96 mentioned is fired in the editor but no response from listener. On device Ad is not shown at all and when I check logs through logcat I see this everytime I try to show ad:
java.lang.ClassNotFoundException: com.unity3d.ads.IUnityAdsShowListener
08-19 09:43:14.667 24240 24292 E Unity : at java.lang.Class.classForName(Native Method)
08-19 09:43:14.667 24240 24292 E Unity : at java.lang.Class.forName(Class.java:454)
08-19 09:43:14.667 24240 24292 E Unity : at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
08-19 09:43:14.667 24240 24292 E Unity : at com.unity3d.player.UnityPlayer.access$300(Unknown Source:0)
08-19 09:43:14.667 24240 24292 E Unity : at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95)
08-19 09:43:14.667 24240 24292 E Unity : at android.os.Handler.dispatchMessage(Handler.java:103)
08-19 09:43:14.667 24240 24292 E Unity : at android.os.Looper.loop(Looper.java:224)
08-19 09:43:14.667 24240 24292 E Unity : at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20)
08-19 09:43:14.667 24240 24292 E Unity : Caused by: java.lang.ClassNotFoundException: com.unity3d.ads.IUnityAdsShowListener
08-19 09:43:14.667 24240 24292 E Unity : … 8 more
08-19 09:43:14.667 24240 24292 E Unity : at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0
08-19 09:43:14.667 24240 24292 E Unity : at UnityEngine.AndroidJNISafe.FindClass (System.String name) [0x00000] in <00000000000000000000000000000000>:0
08-19 09:43:14.667 24240 24292 E Unity : at UnityEngine.AndroidJavaClass._AndroidJavaClass (System.String className) [0x00000] in <000
My code for Ad is here:
using UnityEngine;
using UnityEngine.Advertisements;
public class AdManager : MonoBehaviour, IUnityAdsInitializationListener, IUnityAdsLoadListener, IUnityAdsShowListener
{
[Header("References")]
[SerializeField] EventManager m_EventManager;
[SerializeField] InventoryManager m_InventoryManager;
[Header("Initialize Ads")]
[SerializeField] string _androidGameId;
[SerializeField] string _iOsGameId;
[SerializeField] bool _testMode = true;
[SerializeField] bool _enablePerPlacementMode = true;
private string _gameId;
[Header("Rewarded video Ad")]
[SerializeField] string _androidAdUnitId = "Rewarded_Android";
[SerializeField] string _iOsAdUnitId = "Rewarded_iOS";
string _adUnitId;
public bool videoAdReady;
void Awake()
{
InitializeAds();
// Get the Ad Unit ID for the current platform:
_adUnitId = (Application.platform == RuntimePlatform.IPhonePlayer)
? _iOsAdUnitId
: _androidAdUnitId;
}
public void InitializeAds()
{
_gameId = (Application.platform == RuntimePlatform.IPhonePlayer)
? _iOsGameId
: _androidGameId;
Advertisement.Initialize(_gameId, _testMode, _enablePerPlacementMode, this);
}
public void OnInitializationComplete()
{
LoadAd();
Debug.Log("Unity Ads initialization complete.");
}
public void OnInitializationFailed(UnityAdsInitializationError error, string message)
{
Debug.Log($"Unity Ads Initialization Failed: {error.ToString()} - {message}");
}
// Load content to the Ad Unit:
public void LoadAd()
{
// IMPORTANT! Only load content AFTER initialization (in this example, initialization is handled in a different script).
Debug.Log("Loading Ad: " + _adUnitId);
Advertisement.Load(_adUnitId, this);
}
// If the ad successfully loads, add a listener to the button and enable it:
public void OnUnityAdsAdLoaded(string adUnitId)
{
Debug.Log("Ad Loaded: " + adUnitId);
videoAdReady = true;
}
public void ShowAd()
{
Advertisement.Show(_adUnitId, this);
}
public void OnUnityAdsShowComplete(string adUnitId, UnityAdsShowCompletionState showCompletionState)
{
if (adUnitId.Equals(_adUnitId) && showCompletionState.Equals(UnityAdsShowCompletionState.COMPLETED))
{
Debug.Log("Unity Ads Rewarded Ad Completed");
// Grant a reward.
if(m_EventManager.doubleStarsRewardedVideo == true)
{
m_EventManager.doubleStarsRewardedVideo = false;
m_EventManager.StarsDoubled();
}
if (m_EventManager.secondLifeRewardedVideo == true)
{
m_EventManager.secondLifeRewardedVideo = false;
m_EventManager.SecondLife();
}
if (m_InventoryManager.AddCurrencyRewardedVideo == true)
{
m_InventoryManager.AddCurrencyRewardedVideo = false;
m_InventoryManager.AddCurrencyVideoAd();
}
// Load another ad:
Advertisement.Load(_adUnitId, this);
}
}
// Implement Load and Show Listener error callbacks:
public void OnUnityAdsFailedToLoad(string adUnitId, UnityAdsLoadError error, string message)
{
Debug.Log($"Error loading Ad Unit {adUnitId}: {error.ToString()} - {message}");
// Use the error details to determine whether to try to load another ad.
}
public void OnUnityAdsShowFailure(string adUnitId, UnityAdsShowError error, string message)
{
Debug.Log($"Error showing Ad Unit {adUnitId}: {error.ToString()} - {message}");
// Use the error details to determine whether to try to load another ad.
}
public void OnUnityAdsShowStart(string adUnitId) { }
public void OnUnityAdsShowClick(string adUnitId) { }
}
Thank you in advance if someone could help me how to resolve this.