I have a world selection scene in which I have GameObject
s representing worlds. The GameObject
s 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 GameObject
s 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 GameObject
s 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)
{
Debug.LogError("Could not find save file while loading worlds");
return;
}
foreach (var worldIcon in worldIcons)
{
var savedWorld = saveFile.Worlds.SingleOrDefault(x => x.Number == worldIcon.WorldNumber);
if (savedWorld == null)
{
//add world to save file
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();
}
}
Start
method doesn'tyield 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? \$\endgroup\$