Zosich
December 2, 2019, 2:20pm
1
Hi
Our company has faced an insurmountable problem.
I created a test scene in which 3d characters are loaded in Unity Editor all fine:
Build project, and load to server:
Build AssetBundles and load to server:
and load to server after run and AssetBundles not load:
tried to investigate the problem and found this ifdef:
after comment this block:
This has worked before. Another programmer worked on this, he had to observe many conditions for AssetBundles to work, I tried to repeat these conditions did not help. Rolled back through the version system to earlier working versions, it did not help. In any case, I would like to know and solve the problem fundamentally.
Thanks.
Can you show the code that loads AssetBundle?
Zosich
December 2, 2019, 4:01pm
3
Yes of course. But it is already displayed on the first screen
using System;
using System.Collections;
using System.Collections.Generic;
using AssetBundles;
using UnityEngine;
public class TestLoadAssetBundles : MonoBehaviour
{
private Dictionary<NavHeroes.HeroesEnum, GameObject> HeroAgents = new Dictionary<NavHeroes.HeroesEnum, GameObject>();
public GameObject LoadingSpinner;
private bool requiredHeroesInProcess;
public void OnLoadHeroesClick() {
StartCoroutine(RequiredHeroes(new List<NavHeroes.HeroesEnum>(){NavHeroes.HeroesEnum.Cafe}));
}
public IEnumerator RequiredHeroes(List<NavHeroes.HeroesEnum> neededHeroes)
{
Invoke("ShowSpinner", 1f);
requiredHeroesInProcess = true;
for (int i = 0; i < neededHeroes.Count; i++) {
if (!HeroAgents.ContainsKey(neededHeroes[i])) {
HeroAgents.Add(neededHeroes[i], null);
yield return StartCoroutine(InstantiateHeroAgent(neededHeroes[i]));
}
}
requiredHeroesInProcess = false;
LoadingSpinner.SetActive(false);
}
private IEnumerator InstantiateHeroAgent(NavHeroes.HeroesEnum type) {
string heroName = type.ToString().ToLower();
print("[InstantiateHeroAgent] NavHeroes : InstantiateHeroAgent() heroName =" + heroName);
Debug.Log("█ start LoadAssetAsync");
var request = AssetBundleManager.LoadAssetAsync("heroes/" + heroName + ".unity3d", heroName, typeof(GameObject));
Debug.Log("█ end LoadAssetAsync");
if (request == null)
throw new Exception("InstantiateHeroAgent null request.");
else
Debug.Log("request succsess done!");
request.Reset();
Debug.Log("█ StartCoroutine(request);");
yield return StartCoroutine(request);
Debug.Log("█ try: prefab = request.GetAsset<GameObject>();");
var prefab = request.GetAsset<GameObject>();
if (prefab != null) {
print("prefab = " + prefab.name);
PlaceToNavMesh(prefab);
prefab = Instantiate(prefab, transform);
prefab.GetComponent<CheckStatusOnMap>().SetStatus(true);
prefab.GetComponent<HeroAgent3D>().heroType = type;
}
else Debug.LogError("█ [InstantiateHeroAgent] prefab != null");
HeroAgents[type] = prefab;
}
public void PlaceToNavMesh(GameObject gameObject) {
var trans = gameObject.transform;
gameObject.transform.SetPositionAndRotation(Vector3.zero, trans.rotation);
}
}