- Home /
Unity is working on something, but on what?
Hello guys!
I am working with the Editor script and have a quite complex structure, containing different gameObjects. Before I start some tasks through a separate thread, before that - I am storing different Scripts on those gameObjects into a single list. I call this process "ScriptBaking". That includes using GetComponent for many of those objects at once 200+. It's unavoidable, since I need to store a reference to those script instances, but it's not the problem.
Keep in mind that all of this is happening in the Editor script. I display a progress bar as I am working through the bake process.
This bake process is of course not threaded. It goes well, and takes about 4 seconds to go through all the game objects, I get a nice reference to the scripts. It's okay if I do it again and again, until somewhere at 4th bake - the progress bar starts to really turtle somewhere from 70%. 5th time it will turtle at 60% and so on.
Moreover, I can see that unity is still doing something in the Mac menu. Please have a look at the picture. The progress circle makes a full turn, then starts again?
after some time (4-5 minutes after 5 re-bakes) the progress circle, or pie on the thumbnail hides after several laps. "Bake" is fine once again.
WTF is happening? :D Is it an automatic clean-up some sort? How is the progress circle tied with the turtling of "Baking"?
here is the function, gets invoked on button click from OnInspectorGUI( )
//the variables declared and initialized on the top of the editor script
NodeCounter _nodeCounterShort = GameObject.Find("mainNodeCounter").GetComponent<NodeCounter>();
//Node Counter contains the list of all gameObjects in the scene, "the nodes.
void BakeNS(){
float counter = 1; //used to display progress
foreach(GameObject g in _nodeCounterShort._AllNodesInScene){
NodeSpark _dump = g.GetComponent<NodeSpark>();
_dump._NSneighbour.Clear( );
foreach(GameObject gg in _dump.neighbours){
_dump._NSneighbour.Add(gg.GetComponent<NodeSpark>());
}
EditorUtility.DisplayProgressBar("saving the NodeSparks of neighbours for every node", counter + "/" + _nodeCounterShort._AllNodesInScene.Count, counter/_nodeCounterShort._AllNodesInScene.Count);
counter++;
}
}//end of BakeNS()
And by the way, all the classes are [Serializable] as well as the values in them. However, I am only setting the scripts as dirty only after the Bigger Bake, which I do later with threading.
$$anonymous$$aybe I should use something similar to HideAllFlags? I am pretty similar it's some kind of unnecessary clean up that is done after massive heap of getComponents)
Answer by HappyMoo · Jan 05, 2014 at 02:33 AM
Does anything in your Process create a lot of objects and throw them away again? It could be that after a few starts, you get memory pressure and the Garbage Collector kicks in.
Can you check your memory consumption while running your Baking?
Also, does it help if you call the Garbage Collector yourself after every run?
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
GC.WaitForPendingFinalizers();
But keep in mind that the above may not be the best idea to put in production code - it's just to test if that's the problem. If it is, you would be well advised to try to improve the memory consumption issue.
Hm, placing this at the end of the function didn't have a visible effect :< Unity pie is still displayed, and Bake is turtled :'( Problem disappears if I reimport all the assets of the project, but it's a frustrating solution ))
Your answer

Follow this Question
Related Questions
A node in a childnode? 1 Answer
Network - Editor + Builds = Problem with RayCasts? 0 Answers
How to check if object is skewed ? 2 Answers
Unity-target mainly for design? 1 Answer