- Home /
Standalone build doesn't create gameobjects properly
Hello all,
I'm working on a 2x space game project. In the unity editor when we load the galaxy scene the sample spheres that are there are removed and converted into sun objects with planets. In the standalone build the sample spheres are not removed and no suns or planets are created. Here is a video of my problem hopefully this better explains the behavior: http://www.youtube.com/watch?v=UdyF9yTUyIc&feature=plcp
Some strange behavior: In some builds that we create the game works fine the first time we run it and any time after that it doesn't work
Note: We just use the sample spheres for the suns location so we can create galaxies with the look we want.
This is how we generate the galaxy in code:
galaxyGameObject = Instantiate(galaxyPrefab) as GameObject;
galaxyGameObject.transform.position = GameObject.Find("SampleSuns").transform.position;
Galaxy galaxy = galaxyGameObject.GetComponent("Galaxy") as Galaxy;
GameObject[] sampleSpheres = GameObject.FindGameObjectsWithTag ("Sun");
for (int index=0;index < 100; index ++)
{
GameObject newSunGameObject = Instantiate(sunPrefab) as GameObject;
newSunGameObject.transform.position = sampleSpheres[index].transform.position;
newSunGameObject.transform.parent = galaxyGameObject.transform;
Destroy(sampleSpheres[index]);
Sun newSun = newSunGameObject.GetComponent("Sun") as Sun;
newSun.SunType = CalculateSunOdds(giantSunOdds,commonSunOdds,dwarfSunOdds);
newSun.ReSize();
newSun.PopulateSignatureList();
galaxy.Suns.Add(newSun);
}
Destroy(GameObject.Find("SampleSuns"));
galaxy.printDebugInformation();
Thank you for any help!!!
I don't know why there are two code blocks, apparently I formatted it incorrectly. >.< I tried fixing it but I failed. :(
Answer by Kryptos · Aug 16, 2012 at 01:26 PM
Check for errors (IndexOutOfBound). This line will cause error if there are less than 100 spheres in the scene.
for (int index=0;index < 100; index ++)
Fix it with:
for (int index = 0; index < sampleSpheres.Length; index++)
Won't it be easier to have a dedicated script on each sphere sample that instantiate the sun prefab when the game start.
Something like:
void Awake()
{
Instantiate(sunprefab, transform.position, transform.rotation);
Destroy(gameObject);
}
$$anonymous$$hmmm that's an interesting take on making the sample spheres suns. Obviously that technique never past through our brains when coding this. But with our final presentation tomorrow I don't think we have the time to change this and test it with the rest of the stuff we have to do. Regardless we figured out the problem. It was with our xml reading. After looking at the log file in the build we found out we were getting an IsolatedStorageException because it wasn't finding/reading the xml files we use to populate the planets with data. The solution was simple... include the xml files in the build. >.> Thanks for the help $$anonymous$$ryptos and maybe after this presentation our $$anonymous$$m can look into making the sample spheres suns via their own script.