# How do I properly initialize UDP SDK?

When uploading my game to Unity Distribution Portal (UDP), I kept on receiving this message about sandbox testing:

It seems your game was never tested in the UDP Sandbox environment, as no UDP Initialization call was found on the UDP back-end. Launch your APK in the UDP Sandbox environment to ensure it initializes properly. You must complete this step to release your game.

Now, I initially thought that Unity sandbox testing was enabled as soon as you installed the UDP plugins, but I have read that you need to make a script like this for the testing procedures to pass:

using UnityEngine;
using UnityEngine.UDP;

public class InitListener : IInitListener
{
public void Initialize()
{
StoreService.Initialize(IInitListener listener);
}
public void OnInitialized(UserInfo userInfo)
{
Debug.Log("Initialization succeeded");
}
public void OnInitializeFailed(string message)
{
Debug.Log("Initialization failed: " + message);
}
}


However, I kept on encountering a syntax error that said

InitListener.cs(9,49): error CS1003: Syntax error, ',' expected

...Even though there's no need for a ",".

Typppi also suggested calling from another script to refer to this one, which I have made:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UDP;

public Script listener;
public class Initializer : MonoBehaviour
{
void Start()
{
StoreService.Initialize(IInitListener listener);
}
}


Yet it still returns the same syntax error. Even then, what am I supposed to do with this initialization script? Where do I assign it?

• Initialize(IInitListener listener); this isn't a valid method call though. It looks like a declaration, in a place where you're not declaring a function. So you definitely have some kind of syntax error there. Oct 25, 2020 at 12:55
• So you mean that I should place that function call into another script that initializes at the start? Oct 25, 2020 at 12:58
• No, I'm saying this function call is ill-formed. What is IInitListener doing there? Did you mean to perform a cast of this listener variable? Where is listener declared? Oct 25, 2020 at 13:00
• I think what you want is to have an instance of InitListener live somewhere, and call StoreService.Initialize(instance) with the instance of InitListener you have created from some place that gets called at your game initialization.
– user35344
Oct 25, 2020 at 13:05
• Because you just copied the same code, which I told you was ill-formed, and pasted it somewhere else, without fixing the problem that it's not a valid function call. So the compiler keeps telling you it's wrong, because it is just as wrong as it was before. What do you want to pass as the argument to Initialize? Delete IInitListener listener and put your argument there instead. Oct 25, 2020 at 13:30

The method the official unity documentation mentions is written in a confusingly non-linear way. In your initialization script, both the initialize() function and the OnInitialize() functions have to be in the same script. Thus the actual InitListener script would be:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UDP;
public class InitListener : MonoBehaviour, IInitListener
{
public IInitListener listener;
public void Start()
{
StoreService.Initialize(listener);
}

public void OnInitialized(UserInfo userInfo)
{
Debug.Log("Initialization succeeded");
// You can call the QueryInventory method here
// to check whether there are purchases that haven’t be consumed.
}

public void OnInitializeFailed(string message)
{
Debug.Log("Initialization failed: " + message);
}
}