Hello,
I am encountering an issue when instantiating GameObjects from an AssetBundle where (about half of the time) the object is instantiated with random Rotation values (i.e. X:-7.730941e+11, Y:-7.730941e+11, Z:180) instead of the given rotation. In contrast, performing the same instantiating while having a GameObject reference to the prefab inside the script seems to be accurate 100% of the time.
To illustrate the problem I have attachted a demo project that tests the following scenario’s:
- Instantiate GO reference cube with different position and rotation.
- Instantiate GO reference cube with different position.
- Instantiate GO from AssetBundle with default values.
- Instantiate GO from AssetBundle with different position.
- Instantiate GO from AssetBundle with default value and changes position and rotation after 2 seconds.
using System.Collections;
using UnityEngine;
public class SpawnCubes : MonoBehaviour
{
public GameObject Cube;
// Use this for initialization
void Start()
{
var assetBundle = AssetBundle.LoadFromFile(Application.dataPath + "/AssetBundles/spawnables");
GameObject cubeFromAB = assetBundle.LoadAsset<GameObject>("assets/prefabs/cube.prefab");
GameObject cube1 = Instantiate(Cube, new Vector3(-4f, 0.5f, 0f), Quaternion.Euler(0, 180, 0));
GameObject cube2 = Instantiate(Cube, new Vector3(-2f, 0.5f, 0f), default(Quaternion));
GameObject cube3 = Instantiate(cubeFromAB);
GameObject cube4 = Instantiate(cubeFromAB, new Vector3(2f, 0.5f, 0f), default(Quaternion));
GameObject cube5 = Instantiate(cubeFromAB);
StartCoroutine(moveQube(cube5, new Vector3(4f, 0.5f, 0f), Quaternion.Euler(0, 180, 0)));
}
IEnumerator moveQube(GameObject cube, Vector3 position, Quaternion rotation)
{
yield return new WaitForSeconds(2);
cube.transform.SetPositionAndRotation(position, rotation);
}
}
Executing this code multiple times keeps comming back with different results where sometimes the results are accurate, and sometimes random Rotation values are inserted. Another strange this is that, although random Rotation values are inserted, the objects in the editor seem to be accurate in world space.
So I was wondering, has anyone experienced similar issues, and am I perhaps doing something wrong while loading the prefab from the asset bundle?
Thanks in advance