- Home /
The question is answered, right answer was accepted
Extremely slow to enter playmode (50 seconds) what is the source of the problem?
The game I am working on has fairly peculiar needs, mainly thousands of sprites, each their own gameobject, with code running on them to update them to their appropriate sprite.
The game runs perfectly fine once it is started, easily at 60-70 fps. I have some decent optimization that works well.
When I build the game, it runs well. Loading time is perfectly acceptable, somewhere in the realm of 10 seconds.
The problem is that in the editor, every time I press the play button, I have to wait 50-60 seconds before playback actually starts. I've been trying out different things to figure out what the problem is, but I still can't locate it.
Here are somethings I know.
The more sprites with scripts attached I add, the worse it gets.
If I get rid of the scripts attached to the sprites, it get's much better, even if there are still thousands of game objects.
Here is the main code in the Start() sections of the scripts that are attached the problematic gameobjects.
void Start() {
if (!omniSpritesContentStart) { omniSpritesContentStart = GetComponent<OmniSpriteContent>(); } spriteRenderer = GetComponent<SpriteRenderer>(); growControl = GetComponent<GrowControl>(); newSpriteContent = omniSpritesContentStart.GetSprite(this); spriteRenderer.sprite = newSpriteContent.sprite; StartCoroutine("UpdateSprite"); StartCoroutine(UpdateOmniSpriteData()); }
and
void Start()
{
audioSource = transform.parent.GetComponent<AudioSource>();
if (controlObject)
{
trigger = controlObject.GetComponentInChildren<PopControl>();
}
else
{
// The Grow Control will search for a popcan at in the Same Group level as the plant itself
controlObject = transform.parent.parent.GetComponentInChildren<PopControl>().gameObject;
trigger = controlObject.GetComponentInChildren<PopControl>();
}
omniSprite = GetComponent<OmniSprite>();
}
I feel it's important to note again that the playback on a game build of the game is normal, the load is only about 5 - 10 seconds, but in the editor it's so much longer.
Is there anything obvious that I am missing?
Does anybody have any good information about what is happening after I press the play button, and why it is taking so long. I don't have pro Unity, so I can't use the profiler if that is something that would help.
If you have any ideas, let me know. Perhaps there is some preference I can change to improve this?
Thanks.
Overheads are actually a lot larger in editor than in Build. From what I've seen this is still actually normal.
Coroutines in Start() can also cause delays. Don't forget Coroutines are not multithreaded. Everything still waits for it. Having this code in Start() could well be causing your delay.
Try moving the two Coroutines somewhere else. See what happens.
I fixed the bit of code that was causing the problem and it's all better at a 10 second start up! Fantastic.
THanks for your help
Answer by kylerk · Dec 11, 2014 at 02:03 AM
Found the cause! It was this code. Eck. I see the problem. Traversing up a tree twice was really really stupid. And was causing an explosion in the search size.
controlObject = transform.parent.parent.GetComponentInChildren<PopControl>().gameObject;
trigger = controlObject.GetComponentInChildren<PopControl>();
Ha. Indeed. The parent.parent is actually pretty quick, but as you say greatly increased the size of the GCIC() searches.
Accept your own answer. Published to add good info to the database :)
Follow this Question
Related Questions
Why does object movement get saved to scene editor? 2 Answers
Running a script when Unity starts. 3 Answers
Limit on x rotation axis in play mode 2 Answers
Unity stops after showing splash screen. 1 Answer
Unity Editor Crashes Upon Startup 0 Answers