I have recently switched my Unity project to use the Addressables system to improve asset load speed. Everything works perfectly when I run in Unity playmode, however ONLY when I go to build to Windows or Android (it builds as "successful") but it appears the asset keys just fail to load when running in the build.
*I am using Unity Beta 2021.0.1.0b2 but have tried on the earlier releases.
*My asset is marked as "Addressable" and the addressable is named correctly.
*I "Default Build Script" before I deploy.
*I have tried multiple times even reinstalling Unity and built to both Windows and Android.
*Addressable settings have been "Pack together" and "Pack Separately".
Here is a simplified version of the script (with the exact same error)… that just loads and instantiates an Addressable-marked gameobject (with a UI image attached) from my asset folder onto the canvas when a button is clicked. As per above, this works perfectly in Unity playmode, but fails when I build.
What am I doing wrong? I have been stuck on this for some time now and would really appreciate any help….!
[SerializeField] Button bttn;
[SerializeField] Transform spawnPos;
private void Awake()
{
this.transform.Find("Bttn").GetComponent<Button>().onClick.AddListener(() => LoadPicture());
spawnPos = this.transform.Find("SpawnPos");
}
private void LoadPicture()
{
Addressables.LoadAssetAsync<GameObject>("Drink").Completed += drink =>
{
if(drink.Status == AsyncOperationStatus.Succeeded)
{
GameObject go = drink.Result;
GameObject g = Instantiate(go, transform.position, transform.rotation);
g.transform.SetParent(spawnPos, false);
}
else
{
Debug.Log("Load Failed");
}
};
}
Source: Windows Questions