I'm creating a save manager that does three basic things. 1) Load the first game scene from the start scene. 2) Load a saved game to the last saved scene and checkpoint. 3) Handle a scene change when the player goes through a portal to another scene. Numbers one and two are working as expected. I'm having a problem with number three. The save manager is a singleton object which is created in the start scene. This is the script that is attached to the portal in another scene. The portal's name is the name of the new scene. Code (CSharp): public class PortalName : MonoBehaviour { private string portalSceneName; private GameObject saveSystem; private void Awake() { saveSystem = GameObject.Find("SaveManager"); portalSceneName = gameObject.name; } public void ChangeScenes() { if (saveSystem != null) { saveSystem.GetComponent<GameSaveSystem>().ChangeScenes(portalSceneName); } else { Debug.Log("Save Manager not Found!"); } } } This is the change scene script attached to the save manager: Code (CSharp): public void ChangeScenes(string newSceneName) { UpdateProgressUI(0); loadSceneCanvas.gameObject.SetActive(true); LoadDSGameDataFromSceneChange(); StartCoroutine(BeginLoad(newSceneName)); } The problem is that the portal code is not finding the save manager so it can't pass the name of the object (which is the new scene's name) into the ChangeScenes script. Thanks for any help you can offer.
Are you properly marking it to persist from scene to scene? This is what I reach for: Some super-simple Singleton examples to take and modify: Simple Unity3D Singleton (no predefined data): https://pastebin.com/SuvBWCpJ Unity3D Singleton with Prefab used for predefined data: https://pastebin.com/cv1vtS6G These are pure-code solutions, do not put anything into any scene, just access it via .Instance! If it is a GameManager, when the game is over, make a function in that singleton that Destroys itself so the next time you access it you get a fresh one, something like: Code (csharp): public void DestroyThyself() { Destroy(gameObject); Instance = null; // because destroy doesn't happen until end of frame }
Ha, I figured it out. Yes, the singleton was set up correctly. The problem was in line eight. I was calling "SaveManager". I should have been calling "SaveManager Instance". Thanks for your response.