Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Unity Ads does not initialize upon multiple play sessions in the editor.

Discussion in 'Unity Ads & User Acquisition' started by Spacelab_Games, May 19, 2023.

  1. Spacelab_Games

    Spacelab_Games

    Joined:
    Jun 29, 2017
    Posts:
    81
    I'm currently experiencing a strange scenario with Unity Ads. When I load up my project in Unity and play test the game for the first time in the editor Unity Ads seems to initialize just fine - but if i stop the player and then run another play test in the editor Unity Ads no longer initializes. If I recompile the project then Unity Ads goes through the same scenario - it loads fine on the first play test but not on subsequent play tests.

    I currently have the "Advertisement" package installed (v. 4.3.0) and prior to that i had the legacy version installed (v. 4.4.2) and I'm getting the same issue regardless of which one is installed. I'm also confused on which one should be installed...under "Project Settings" it states that 4.4.2 is the latest version and provides an "Install Latest Version" option but under the package manager it recommends installing version 4.3.0...confusing S*** to say the least.

    I'm also using the code provided in the Unity docs to initialize Unity ads without any modifications on my part:
    https://docs.unity.com/ads/en/manual/InitializingTheUnitySDK
    https://docs.unity.com/ads/en/manual/ImplementingBasicAdsUnity

    I'm guessing this is a bug I'm experiencing but I'm not 100% sure.

    If anyone can shed some light on my issue I would appreciate the help. I can provide screenshots or a video reference of my issue upon request.

    Thanks.

    -Leo
     
  2. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    626
    Hi Leo, could you confirm if the initialize method of Unity Ads SDK has been called in the subsequent play tests? If yes, are there any error logs you can provide?
     
  3. Spacelab_Games

    Spacelab_Games

    Joined:
    Jun 29, 2017
    Posts:
    81
    Hi,

    I'm not getting any errors in the console. The first time i play my game in the editor the "OnInitializationComplete" callback fires and the ads are working as expected - i also see the debug statement "Unity Ads initialization complete." in the console. On subsequent plays the "OnInitializationComplete" callback doesn't seem to execute nor does the "OnInitializationFailed" callback.

    In the "InitializeAds" function I modified the code to the following:

    Code (CSharp):
    1.  
    2. if (!Advertisement.isInitialized && Advertisement.isSupported)
    3.         {
    4.             Advertisement.Initialize(_gameId, _testMode, this);
    5.         }
    6.         else
    7.         {
    8.             Debug.Log("-- Unity Ads did not initialize. --");
    9.         }
    10.  
    On subsequent plays the second part of the if statement executes.

    Here is a video reference of what I'm experiencing:
    https://www.spacelabgames.com/files/videos/unity_ads.mp4

    -Leo
     
  4. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    626
    I used the below code and didn't reproduce this problem, could you have a try?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Advertisements;
    5.  
    6. public class NewBehaviourScript : MonoBehaviour,IUnityAdsInitializationListener
    7. {
    8.     // Start is called before the first frame update
    9.     void Start()
    10.     {
    11.         if (!Advertisement.isInitialized && Advertisement.isSupported)
    12.         {
    13.             Advertisement.Initialize("1234567", true, this);
    14.         }
    15.         else
    16.         {
    17.             Debug.Log("-- Unity Ads did not initialize. --");
    18.         }
    19.  
    20.     }
    21.  
    22.     void IUnityAdsInitializationListener.OnInitializationComplete()
    23.     {
    24.         Debug.Log("-- OnInitializationComplete --");
    25.     }
    26.  
    27.     void IUnityAdsInitializationListener.OnInitializationFailed(UnityAdsInitializationError error, string message)
    28.     {
    29.         Debug.Log("-- OnInitializationFailed --");
    30.     }
    31. }
    32.  
     
  5. Spacelab_Games

    Spacelab_Games

    Joined:
    Jun 29, 2017
    Posts:
    81
    Hi,

    Unfortunately that code made no difference on my end. I tested with Advertisement Legacy 4.4.2 and Advertisement 4.3.0 and I'm still experiencing the same issue.
     
  6. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    626
    Can you reproduce the problem by creating a new project and using this code? If yes, please provide the project and I'll test it on my end, if not, then it may be a problem specific to your project, we need to check it further.