- Home /
Instantiate at runtime works with Editor but freaking strange behavior at standalone build
Hi all, thanks for visiting!
I have problem with instantiating prefabs at runtime.
It was done successfully a while ago
private GameObject Instantiate(ISFSObject entity) { GameObject representation = bucketPrefab; if (entity.ContainsKey("look")) { int entityRepresentation = entity.GetInt("look"); switch(entityRepresentation) { case 0: representation = Resources.Load("alpha_midres", typeof(GameObject)) as GameObject; break; case 1: representation = Resources.Load("beta_midres", typeof(GameObject)) as GameObject; break; } if (representation == null) { Debug.LogError(DateTime.Now.ToString() + " Instantiate: Look is: NULL"); } Debug.Log(DateTime.Now.ToString() + " Instantiate: Look is: " + representation.ToString()); } ClientMapManager mapMgr = (ClientMapManager)GameObject.Find("MapManager").GetComponent("ClientMapManager"); if (mapMgr == null) { Debug.LogError(DateTime.Now.ToString() + "Instantiate: ClientMapManager is: NULL"); } Vector3 position = GetPositionFromSnapshot(entity); if (position.Equals(Vector3.zero)) { Debug.LogError(DateTime.Now.ToString() + " Instantiate: New entity has no position!: " + entity.ToString()); position = new RGB(0,0).Center * Hex.Side; } Quaternion orientation = GetOrientationFromSnapshot(entity); if (orientation.Equals(Quaternion.identity)) { orientation = representation.transform.rotation; Debug.LogError(DateTime.Now.ToString() + " Instantiate: New entity has no orientation!: " + entity.ToString()); } return (GameObject)UnityEngine.Object.Instantiate(representation, position, orientation); }
It appeared to work bad at built client
It still works just fine in the Editor
According to logs position, rotation and prefab are fine
GameObject newInst = Instantiate(newPair.Value); if (newInst == null) { Debug.LogError(DateTime.Now.ToString() + " UpdateViewFormSFS: newInst is: NULL"); return; } Debug.Log(DateTime.Now.ToString() + " UpdateViewFormSFS instantiated: " + newInst.ToString() + " at pos: " + newInst.transform.position.ToString() + ", rot: " + newInst.transform.rotation.ToString());
On the built client it actually looks like prefab quickly flying on a spiral track to center of the screen, then shivering at mid and then disappearing. Sometimes I dont see them at all.
But it doesnt happen to all prefabs, only to human prototypes from mixamo
These prefabs are in Resource folder
Any inputs or ideas how to diagnose it?
PS: code formatting is either broken here or I'm stupid. Tried to make it work for 10 minutes now
But HOW??? I tried code button and also read http://daringfireball.net/projects/markdown/syntax#precode about spaces and tabs: nothing works...
Your answer
![](https://koobas.hobune.stream/wayback/20220613161452im_/https://answers.unity.com/themes/thub/images/avi.jpg)