- Home /
Scene takes a long time to load
I'm working on a tower defense game and currently I'm running into a problem with my last 2 levels and setting up an endless wave mode. My issue is that it tries to instantiate all the objects prior to loading and this has caused my game to slow on loading the level (one takes 3.5 minutes, the other takes 30+ minutes). Currently having some issues so a little help would be greatly appreciated.
I understand that I would want to set it to instantiate the objects when the wave is called, I'm just having an issue with getting the code layout because I'm still very new with the coding aspect of the game. Presently using C# so if you could follow suite that would be nice.
Thank you in advanced
show source pieces of objs instantiates and starts of move
//spawning call for individual wave //from here, multiple spawn routine for each creep type in the wave is called public void SpawnWave(){ //Debug.Log("spawn wave "+(currentWave+1)); Game$$anonymous$$essage.Display$$anonymous$$essage("Inco$$anonymous$$g wave "+(currentWave+1)+"!");
Audio$$anonymous$$anager.PlayNewWaveSound();
//disable user initiated spawning until current wave has done spawning isClearForSpawning=false; ClearForSpawningE(isClearForSpawning);
foreach(SubWave subWave in waves[currentWave].subWaves){ StartCoroutine(SpawnSubwave(subWave, waves[currentWave], currentWave)); }
StartCoroutine(CheckSpawn(currentWave));
currentWave+=1; if(WaveStartSpawnE!=null) WaveStartSpawnE(currentWave+1); }
//actual spawning routine, responsible for spawning one type of creep only IEnumerator SpawnSubwave(SubWave subWave, Wave parentWave, int waveID){ yield return new WaitForSeconds(subWave.delay); int spawnCount=0; while(spawnCount(); UnitCreep unit=obj.GetComponent(); if(subWave.overrideHP>0) unit.SetFullHP(subWave.overrideHP); if(subWave.override$$anonymous$$oveSpd>0) unit.Set$$anonymous$$oveSpeed(subWave.override$$anonymous$$oveSpd); unit.Init(tempPath, waveID);
parentWave.activeUnitCount+=1;
spawnCount+=1; if(spawnCount==subWave.count) break;
yield return new WaitForSeconds(subWave.interval); }
subWave.spawned=true; }
A friend of $$anonymous$$e wrote the code so I have to muck with it until I get the handle of coding myself so I do apologize if it is a bit messy or I seem like I don't know what I'm doing ( I really don't yet).
Something that I was looking at doing was putting in a
for (int i = 0; i < numberOfWaves; i++)
into it to help with the call for every object that will be placed into the game.
hmm. did you found exactly a lines where Application works for these $$anonymous$$utes?
this piece of code looks rather correct. it can be slow but in runtime, not at loading.
Answer by TDGuy · Aug 06, 2012 at 11:41 PM
Ok, first thank you for everyone that looked at this and thank you ScroodgeM for your assistance with helping me weed out my issue. you are correct that the code is fine and what I found is that the issue was the fact that my code was calculating all of the information all at once which is why it was taking a long time. I went the route of utilizing a for loop to calculate the HP instead of setting the hp initially.
Again, thank you for your help.