When the path to the layout file is dynamically assembled directly in the call to CreateWidgets, it sometimes fails to create widgets (returned widget is either NULL or not of the expected type).
Sporadically failing example:
Widget widget = GetGame().GetWorkspace().CreateWidgets( "path/to/layoutfiles/" + rows.ToString() + "/GridSpacer" + columns.ToString() + ".layout", parent );
The work-around is to assemble the path outside the call, and then passing it in:
Working example:
string layout = "path/to/layoutfiles/" + rows.ToString() + "/GridSpacer" + columns.ToString() + ".layout"; Widget widget = GetGame().GetWorkspace().CreateWidgets( layout, parent );