# Updating object's property on Start is visible for a second when game loads

I have a world selection scene in which I have GameObjects representing worlds. The GameObjects have default properties when the scene is loaded. For example: the world name text is red and each world has a "locked" status. This initial state can be seen in the following screenshot:

On the Start() method I'm dynamically updating the properties on each GameObject based on values I'm reading from a save file. If a world is unlocked the name text is set to white. If a world is currently selected the name text is set to green. Here's what that looks like at run time:

The problem is that when the scene is loaded from another scene(e.g. by clicking a navigation button) the initial state of the GameObjects can be seen for a second and then they change to the proper values as dictated by the save file. How can I prevent this from happening? I was under the impression that anything that happens in the Start() method takes place before GameObjects are rendered.

Here's some slimmed down code of what my code looks like:

    var worldIcons = FindObjectsOfType<WorldIcon>().OrderBy(x => x.WorldNumber).ToList();
var saveFile = GameSaveManager.GetSaveFile();

if (saveFile == null)
{
return;
}

foreach (var worldIcon in worldIcons)
{
var savedWorld = saveFile.Worlds.SingleOrDefault(x => x.Number == worldIcon.WorldNumber);

if (savedWorld == null)
{
GameSaveManager.CreateWorld(worldIcon.Controller);

//unlock first world by default
if (saveFile.Worlds.Count == 0 && worldIcon.WorldNumber == 1)
worldIcon.Unlocked = LevelMapController.LockedStatus.Unlocked.ToString();
}
else
{
worldIcon.DisplayName = savedWorld.Name;
worldIcon.WorldNumber = savedWorld.Number;

var button = worldIcon.GetComponent<Button>();

if (savedWorld.Unlocked)
{
button.interactable = true;
button.targetGraphic.color = Color.white;
worldIcon.Unlocked = LevelMapController.LockedStatus.Unlocked.ToString();
}
else
worldIcon.Unlocked = LevelMapController.LockedStatus.Locked.ToString();
}
}

• What you describe as your expected behavior is indeed what should happen. If the script is enabled and the Start method doesn't yield return, then the method will run to completion before the scene is rendered for the frame that the objects have spawned. Can you walk us through the steps to build a Minimal Complete Verifiable Example, so we can reproduce this problem without access to your scene files or the rest of your loading code? – DMGregory Jan 22 at 11:23
• I have seen some instances where the UI needs an extra kick to process layout changes that occurred during the frame, before drawing. So it might be your Start method is getting called when you expect, but for some reason the UI fails to update its cached drawing state before the render happens. It might be worth checking if the UI elements you're using or their containers expose some type of SetDirty/Rebuild method you can poke to remind them to update themselves. – DMGregory Jan 23 at 13:57

I finally figured out what was going on. It turns out that it only looked like the World GameObjects weren't initialized before the scene was rendered. Each world GameObject has a button whose Target Graphic property is set to a child Text object called DisplayName. This child object displays the world's name(World1, etc.) The button's Fade Duration property is set to 0.1 by default. The problem was fixed by changing this property to 0.
• "No"? The chart you've linked to does indeed show Start is called before the object is rendered for the first time (provided the script is enabled). It will run to completion in a single frame — even if it has to stop and load a file along the way, it will just delay the rendering rather than drawing part-way through — unless the code explicitly makes it a coroutine and has a yield return that lets the current frame finish rendering before the method resumes. – DMGregory Jan 22 at 11:19
• The execution order diagram, as @DMGregory pointed out, is what led me to believe that the properties I change would be applied before the object is rendered for the first time. I don't believe I have any yield return calls anywhere in the initialization code but I will double-check later today. – Bruno Jan 22 at 14:15