Upgrading Unity v5.3.5 to UnityAds v2.0 seems to generate an error?

Hello, I am new to UnityAds and I am having some confusing issues while preparing implementation.

I have a project in Unity v5.3.5 and implemented Unity Ads(v1.5x) in test mode, and everything seemed to work correctly (even in Android builds).

I recently noticed that <5.5 versions don’t implement Unity Ads v2.0, and that v1.5.x is deprecated as stated in this thread:

So, following the upgrade guide, I completed the steps, tried again in test mode and everything seems to be working correctly once again. Have I to assume that this means previous embedded GUI’s Unity Ads options in editor are deprecated from now on? If I did understand things well, it seems that this affirmation is true, in which case from now on I have to use the initialization script for Ads configuration.

That said, I have a function to show ads when appropiate, called when needed. It looks like this:

//Updated by adding Time.deltaTime in each frame
private var ad_timer : float = 300.0f;

function ShowAd() {
    if (ad_timer > 300.0f) {
        if (Advertisement.IsReady()) {
            Advertisement.Show();
            ad_timer = 0.0f;
        }
    }
}

I call it when player is explicitly restarting a level or going to Main Menu (directly, not as a coroutine). However, I saw this answer in Stack Overflow while googling for documentation, which makes me wonder if I should consolidate the advertisement calls inside coroutines or not.

But something even more concerning: since I upgraded to Unity Ads v2.0, I have made one more test in a development build for Android. Ad showing still works, but, even through I am setting “testMode = true” in:

    Advertisement.Initialize(gameId, testMode);

…the builded app seems to be showing me a real ad - I clearly saw some game’s footage -, instead of the “Unity Test Ad” that I used to see with Unity Ads 1.5x! This confuses me because I have checked the build as “Development Build” before building, and I don’t want to generate real calls to the services until I assure the implementation is solid enough for release, and everything is ready for production deployment.

What is going on actually? Did the “test add” change for Android, or did something gone wrong? Should I make a bug report about this issue?

Yes, unfortunately there can still be some confusion, especially when using Unity versions before 5.5 (which has Ads SDK 2.0 integrated, as you write)

However I’m confident that testmode works, since we’re using this in our test automation. You have disabled the engine integrated Ads SDK, right? (otherwise you would likely have got “defined multiple times” compiler messages during build)

You are welcome to send me your game id in private message, so I can verify from here.

/Rasmus

@rasmus-unity

Thank you very much for your rapid response. You made me think on something. The inicialization script includes:

    #if UNITY_ANDROID
    gameId = androidGameId;
    #elif UNITY_IOS
    gameId = iosGameId;
    #endif

…which I assume switches between specific IDs for Google Play and Apple stores, instead of Project UPID (I might misunderstood it). Perhaps, my guess that these IDs aren’t needed for test mode is wrong? And if so, must I pass UPID to initialization method even for testing?

I think that wrong guess of mine might be causing this issue, so I will search for the related API documentation, to make sure I am not initializating wrongly…

EDIT

You should not be able to watch ads if you are not providing the game id for the correct platform (i.e. Android/iOS)

Please check from the device log that the game id used by Ads SDK is the expected one. The log should contain something like “Initializing Unity Ads (version) with game id (id)”

/Rasmus

Ok. I shall prepare one more test in the device while monitorizing the logs, to watch about it. However, quoting what you said:

“You should not be able to watch ads if you are not providing the game id for the correct platform (i.e. Android/iOS)”

I guessed the IDs would be ignored in test mode. Otherwise, I used the initialization code sample “as it was”, and didn’t change ID values at all. Perhaps this error of mine is causing the issue.

If IDs aren’t ignored by Advertisement.Initialize() during test mode, that might mean that it is using wrong IDs to make the calls!
That said: I take note from the IDs defaulted in the sample initialization, and I am going to check for it in the device logs. I will be back when I get the result. Thank you.

@rasmus-unity

I verified the logs. Indeed, it is passing the Android ID defaulted in the sample initialization script (which was 18658). It is clearly parsing this ID when calling UnityAds server. So it seems I am initializating wrongly

Now there’s no doubt: it’s my fault.

I will try to make another test leaving IDs blank, to see if test mode works correctly this time.

EDIT:
I owe you one more clarification: I left Unity Ads switch off in all these tests of v2.0 (the previous v1.5x embedded switch I mean). Both versions entered in conflict and didn’t let to compile, so there was no way around it.

I left IDs blank and tried again both in Android Development Build and inside Editor. This time, no ad is being shown (no testmode ones, nor real ones either) in both cases.

No errors prompted during Editor test (I remember some snippets I found that could help me spotting the error by generating logs, while I was surfing the web for documentation. I will try to refind them, due to I can test faster through the Editor than checking Android logs.

If I don’t find any initialization errors in Editor this way, I will try again reading Android logs to spot the cause. I’m expecting to receive a log like “gameID needed” or similar.

From Editor’s logs, I can get that “Advertisement.isInitialized” equals true, but I never get an “Advertisement.isReady()” returning true. So from editor I only get a bunch of (not ready) tries. It could be to network issues this time…

I will not get anything clear of just testing and testing again today if there are network problems… so I’ll take this on tomorrow.

So far, I have got a question:

Is “processing Android and iOS IDs” “expected behaviour” with testMode initialization?

EDIT:
This line from Android logs seems to be pointing that “YES”:

com.unity3d.ads.UnityAds.initialize() (line:115) :: Error while initializing Unity Ads: empty game ID, halting Unity Ads init

EDIT2:
In the integration guide I found a comment referring to “androidGameId = 18658” being a testing ID… if so, why did it impress a real ad?

EDIT3:

This starts to make sense… so I went back to the Integration guideand saw something I didn’t see before:

There I realized the actual mess my head had became to… at least, the issue was solved.

THE CAUSE:
A complete misunderstanding about how IDs are handled in TestMode. If I just scrolled down a little more instead of searching like crazy on the web, I could have prevented this whole mess…

I am sorry for the inconvenience.