loading gameobjects during scenechange

Hello everyone,

I am attempting to make a save and load feature for my game in unity 5.5.
It works reasonably well already, I can save and load my data and when I am in the required scene everything is loaded correctly.
But when I load from my main menu I prompt a scene changes after which I initialize my game objects, but when the game is done loading everything is empty.

I figure this happens because the game objects are made before the scene finishes loading and thus when the scene does change it goes into a empty scene because everything was loaded into the old one. Now what I don’t know how ever is how to fix this problem.

This is my current code:

 public void LoadGame(int loadNumber){
	SceneManager.LoadScene("Scenes/Prologue");

	if (File.Exists(Application.persistentDataPath + "/playerInfo" + loadNumber + ".dat"))
	{
		BinaryFormatter bf = new BinaryFormatter();
		FileStream file = File.Open(Application.persistentDataPath + "/playerInfo" + loadNumber + ".dat", FileMode.Open);
		SaveGameData data = (SaveGameData)bf.Deserialize(file);
		file.Close();

		InitaliseGameComponents();

		var eventString = _GameProgress.Load(data.GameProgressData);
		var splitEventString = eventString.Split(':');
		if (data.DialogData != null)
		{
			_DialogControl.Load(data.DialogData, splitEventString[1], splitEventString[2]);
			_DialogDisplay.SetActive(true);
		}
		if (data.CombatData != null)
			_CombatControl.Load(data.CombatData);
	}
}

Even though the SceneManager acts first the gameobjects that are being created in the _CombatControl are unloaded. Does anyone know a good fix for this? Or am I doing something fundamentally wrong?

Thank you in advance.

Depending on your specific needs, you will either need to run the initialization of those objects after the scene load has happened, load the scene additively, or mark those objects as Don’t Destroy on Load.

A common technique used would be to load a “Loading Level” from your MainMenu, for example a scene with a loading texture and some game tips or something, then load your game scene additively, initialize your saved state, and finally unload your loading scene (or leave it there and use it again as needed).

All three of those options should work, so choosing which one makes the most sense for your project and needs is the real question.