Hey everyone,
I’m having a bit of a trouble getting Unity Ads to work. I have installed the plugin through the Unity package from the asset store, but when ever I’m trying to run the game in the editor I get this exception.
This is my current implementation:
public override void Initialize()
{
m_minInterval = Config.GetValue<float>( "unityads-min-interval", m_minInterval );
m_minNavigations = Config.GetValue<int> ( "unityads-min-navigations", m_minNavigations );
m_interstitialScreens = Config.GetValue<Dictionary<string, bool>>( "unityads-interstitial-screens", null );
#if UNITY_ANDROID || UNITY_IOS
if ( Advertisement.isSupported )
{
Advertisement.allowPrecache = true;
#if UNITY_ANDROID
Advertisement.Initialize( m_androidGameId, m_testMode );
#elif UNITY_IOS
Advertisement.Initialize( m_iosGameId, m_testMode );
#endif
}
else
{
Debug.Log( "Advertisments not supported on current platform!" );
}
#endif
m_navigationsFromLastAd = 0;
m_lastAdTimestamp = Time.realtimeSinceStartup;
SetReady();
}
...
...
private void TryShowInterstitial( string screenName )
{
if ( m_interstitialScreens != null && m_interstitialScreens.ContainsKey( screenName ) && m_interstitialScreens[ screenName ] == true )
{
#if UNITY_ANDROID || UNITY_IOS
if ( Advertisement.isInitialized && Advertisement.isReady() && !Advertisement.isShowing )
{
m_navigationsFromLastAd = 0;
m_lastAdTimestamp = Time.realtimeSinceStartup;
Advertisement.Show( null, new ShowOptions { pause = true } );
}
#else
// Counter resets on non supported platforms for debugging purposes only
m_navigationsFromLastAd = 0;
m_lastAdTimestamp = Time.realtimeSinceStartup;
Debug.Log( "-- Interstitial will play here --" );
#endif
}
}
Setting build configuration to anything other than Android or iOS works as expected (well, everything is ifdef’d out, no surprise there). But as soon as I switch the target platform to either Android or iOS I get the following runtime exceptions as soon as a method containing reference to Advertisements is invoked:
Calling Initialize():
TypeLoadException: Could not load type ‘UnityEngine.Advertisements.Advertisement’ from assembly ‘Assembly-CSharp’.
Game.Update () (at Assets/Shared/Scripts/Game/Game.cs:74)
And if I comment out the whole initialization block and left it reach TryShowInterstitial() I get this one:
TypeLoadException: Could not load type ‘UnityEngine.Advertisements.ShowOptions’ from assembly ‘Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’.
UnityAdsManager.OnMenuScreenShown (.MenuScreen screen) (at Assets/Shared/Scripts/UnityAdsManager.cs:81)
MenuScreen.Show () (at Assets/Shared/Scripts/UI/MenuScreen.cs:46)
MenuManager.SetScreen (System.String screen, Boolean resetNavigation) (at Assets/Shared/Scripts/UI/MenuManager.cs:98)
ScreenIntro.Update () (at Assets/Scripts/Screens/ScreenIntro.cs:28)
The odd part about it is it does not throw this exception at start up, but only when a method containing a reference to Advertisements is invoked - but even without any actual call to Advertisements (i.e. in the case of TryShowInterstitial() it will throw the exception as soon as the method is invoked, even if it were to fail the first conditional test and never actually call anything from Advertisements).
Some additional specs:
Using Unity 4.5.4f1.
Using NGUI (relatively recent, don’t think it’s relevant in any way)
Using Google Analytics official plugin (latest release as of writing this)
API Compatibility level set to .NET 2.0 Subset
Testing in editor, reproduces identically when target platform is either Android or iOS.
Sorry for the wall of text ![]()
Would appreciate any information or ideas on how to resolve this. So far Googling and searching this forum turned up nothing.
Thanks!