I’m experiencing a very strange problem:
I’m building my scene procedurally, when the game starts for the first time, I preform all the calculations in memory and build all the GameObjects and Meshes on the fly, meanwhile I save data to disk, when the game starts by a second time I build the scene from the previously recorded data.
The resulting scene is exactly the same no matter if I do the calculations in memory or if I read the data from disk, however I’m experiencing a severe performance loss when the scene is built from disk. At first I though my Meshes were contaminated with garbage due to an error in the recorded info, but after validating the data I’m sure that’s not the case. During my tests I noticed this strange behavior: If I go to the hierarchy and select a GameObject which has a Rigidbody attached, performance automatically returns to normal, but if I click on any object with no Rigidbody attached, performance drops dramatically again.
This is what I see on the profiler when the selected object in the hierarchy has no Rigidbody attached. As you can see Gfx.WaitForPresent and ParticleSystem.Update eat up almost all the frame’s time.
This is what I see when I select a GameObject with a Rigidbody attached, which is more or less the same frame rate I get when I build the whole thing from memory.
I built the Windows Stand Alone Player to see if this was an Editor exclusive problem, but there’s is also a notorious performance loss when the scene is assembled from disk data, and in the profiler I see the same two functions eating up time like pop corn.
My first approach to debug this problem was to use the class shown below to save the meshes from the editor menu in order to completely skip my algorithm and compare the results produced by the Build and Load processes… In all cases both meshes were the same size, vertex count and triangle count. To be sure I wrote a verification function to read the mesh data just after writing it, and no recording errors were found.
using UnityEngine;
using UnityEditor;
public class SaveMesh {
[MenuItem("Tools/Save Mesh")]
private static void DoIt(){
GameObject obj = Selection.activeGameObject;
if(obj==null){
Debug.LogError("You must select a GameObject in order to save its mesh.");
return;
}
MeshFilter mfl = obj.GetComponent<MeshFilter>();
if(mfl==null) {
Debug.LogError("Object doesn't have a mesh filter.");
return;
}
Mesh msh = Mesh.Instantiate(mfl.sharedMesh);
AssetDatabase.CreateAsset(msh,"Assets/Meshes/"+obj.name+".asset");
AssetDatabase.SaveAssets();
}
}
When the scene is built from memory, performance remain unaltered by your selection on the hierarchy but after saving a mesh with the code above from the editor’s menu, the problem pops up, so the scene exhibits the same behavior as if it was built from disk. So it makes me think that this problem is triggered by the file system itself, can’t figure out why or how, but I strongly believe a file operation is involved in triggering this behavior.
Another unexpected thing is that, the frame rate doesn’t improve by deleting the particle system, instead Gxf.WaitForPresent takes more time to complete, as shown below.
One more strange thing is that, when a GameObject without Rigidbody is selected, performance on the GPU is at a normal rate, however if the selected object has a Rigidbody then performance on the GPU drops notoriously.
The white line marks the point in which I changed the selection on the hierarchy.



