Search Unity

Ads Causing Unity to Crash on Startup of Program

Discussion in 'Unity Ads' started by Tim-Duval, Mar 13, 2019.

  1. Tim-Duval

    Tim-Duval

    Joined:
    Sep 2, 2015
    Posts:
    366
    This is my first time attempting to implement ads. I have everything I need installed and followed all of the steps. I even resorted to copy/paste the code off the unity guide page.

    My first thought is maybe the fact I have my program set into portrait mode only and additionally I don't have my Game view set to any custom size MIGHT have something to do with this. You'll see I'm Free Aspect
    GameCamView.jpg

    I also made sure the ads and test modes were enabled to conduct the test
    Ads-On.JPG TestMode-On.JPG

    Here is the code I'm using
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Monetization;
    5.  
    6. public class VideoAds : MonoBehaviour
    7. {
    8.     private string store_id = "111111"; // I edited random numbers here but mine is the correct in my code
    9.     private string vidAd = "video";
    10.     private bool testMode = true; // This needs to be FALSE before publishing
    11.  
    12.     private void Start()
    13.     {
    14.         Monetization.Initialize(store_id, testMode); // Change testMode to FALSE before publishing
    15.         ShowAd();
    16.         //StartCoroutine(ShowAd());
    17.     }
    18.     public void ShowAd()
    19.     {
    20.         StartCoroutine(ShowAdWhenReady());
    21.     }
    22.  
    23.     private IEnumerator ShowAdWhenReady()
    24.     {
    25.         while (!Monetization.IsReady(vidAd))
    26.         {
    27.             yield return new WaitForSeconds(0.25f);
    28.         }
    29.  
    30.         ShowAdPlacementContent ad = null;
    31.         ad = Monetization.GetPlacementContent(vidAd) as ShowAdPlacementContent;
    32.  
    33.         if (ad != null)
    34.         {
    35.             ad.Show();
    36.         }
    37.     }
    I got this code from the unity website. However, Unity crashes upon play.
    https://unityads.unity3d.com/help/unity/integration-guide-unity

    I'm using Unity 2019.1.0a10
     
  2. TARTs

    TARTs

    Joined:
    Jan 2, 2013
    Posts:
    73
    Go to services > Ads > Turn off built in ads

    Remove
    -Plugin/Android
    -Plugin/iOS

    Re-Import Unity ADS from asset store

    ( Do not check build-in ads extension )
     
    Tim-Duval likes this.
  3. Tim-Duval

    Tim-Duval

    Joined:
    Sep 2, 2015
    Posts:
    366
    Ok, I unchecked built in ads and that did work!

    However, I believe the true cause of my crash/error was a much different issue. I discovered Scripting Runtime Version under Edit>Project Settings>Player. I was using ,NET 3.5(Depreciated) and I changed it to .NET 4.x Equivalent. This made my program stop crashing on run time. Your advice to uncheck actually made the test video appear.

    Thank you! :)