- Home /
GUILayout performance problems
I'm building a simple editor window that logs the assets that are not used in the build. In a nutshell, what I want to do is present the list of assets paths, with two controls, one next to the other: Button - SelectableLabel
Where the button opens the container folder for that asset, and the SelectableLabel holds the path to the asset.
I'm trying to do it using GUILayout with this code:
scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
foreach(var assetFilepath in assetCollection)
{
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Open folder", GUILayout.Width(100)) )
{
System.Diagnostics.Process.Start( GetAssetFolder(assetFilepath) );
}
EditorGUILayout.SelectableLabel(assetFilepath, GUILayout.Height(15));
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.EndScrollView();
While this looks fine, the problem is that with a large number of files the GUI is unresponsive and sluggish, due to defining a layout for each Button/Label pair in the foreach loop. I've test this: if I remove the Begin/EndHorizontal calls inside the foreach, it works fine (but obviously the controls are not positioned like I want).
Does anyone has a workaround that allows using an automatic layout while avoiding this performance penalty or I need to fallback to manually positioning the button & label?