- Home /
Unity freezes for for some time on pressing play. Profiler shows Awake is delaying
I have a heavy load once I press play. It takes as you see 103 seconds for it to start. It seems it has many calls within the Awake on in the Outline class. Outline is a free asset from asset store called "Quick Outline"
This is how the Awake method looks like in the Outline class:
void Awake()
{
// Cache renderers
renderers = GetComponentsInChildren<Renderer>();
// Instantiate outline materials
outlineMaskMaterial = Instantiate(Resources.Load<Material>(@"Materials/OutlineMask"));
outlineFillMaterial = Instantiate(Resources.Load<Material>(@"Materials/OutlineFill"));
outlineMaskMaterial.name = "OutlineMask (Instance)";
outlineFillMaterial.name = "OutlineFill (Instance)";
// Retrieve or generate smooth normals
LoadSmoothNormals();
// Apply material properties immediately
needsUpdate = true;
}
void LoadSmoothNormals()
{
// Retrieve or generate smooth normals
foreach (var meshFilter in GetComponentsInChildren<MeshFilter>())
{
// Skip if smooth normals have already been adopted
if (!registeredMeshes.Add(meshFilter.sharedMesh))
{
continue;
}
// Retrieve or generate smooth normals
var index = bakeKeys.IndexOf(meshFilter.sharedMesh);
var smoothNormals = (index >= 0) ? bakeValues[index].data : SmoothNormals(meshFilter.sharedMesh);
// Store smooth normals in UV3
meshFilter.sharedMesh.SetUVs(3, smoothNormals);
}
// Clear UV3 on skinned mesh renderers
foreach (var skinnedMeshRenderer in GetComponentsInChildren<SkinnedMeshRenderer>())
{
if (registeredMeshes.Add(skinnedMeshRenderer.sharedMesh))
{
skinnedMeshRenderer.sharedMesh.uv4 = new Vector2[skinnedMeshRenderer.sharedMesh.vertexCount];
}
}
}
I do have a lot of MeshesRenderer:s, is that what is taking so long time on load up? If this Component is created at a later stage the delay is not there. Only when this component is created initially.
The number of meshes you have could very well be the problem. Comment out the LoadSmoothMeshes() method and see how your time improves
Thanks @Zaeran, I commented out the LoadSmoothNormals() and problem disappeared. I had about 900 MeshRenderers, I though GetComponentsInChildren(); would cost most but something in LoadSmoothNormals takes much more time. Thanks:)