Loading game from Main Menu

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
kilfeather94
Posts: 17
Joined: Sat Jan 23, 2016 1:35 pm

Loading game from Main Menu

Post by kilfeather94 »

Hi,

I'm just having difficulty with saving and loading the game. Basically, my problem is, I can only successfully load my game whenever I'm in a scene that has my player character with it. In the first level of my game after the Main menu scene, I have my Dialogue System Controller, with the Level Manager and Game Saver components. I also have a Persistent Data Template component on another gameobject which handles all of the persistent data. I am able to save and load between different scenes just fine, and keep stuff persistent like Weapons, which I got help from you before with.

I can't seem to load stuff successfully from the Main menu. I added a Dialogue System controller object into the main menu and added the Level Manager and Game Saver components to it. When I load from the Main menu, it will bring me to the scene where I last saved, which is what I want, but my Camera and Player character and everything I need is missing.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Loading game from Main Menu

Post by Tony Li »

Hi,

Are you using any third party assets for your player and camera? If so, which one(s)?

In the main menu scene, is your persistent data component perhaps saving invalid info for your player position since there's no player in the scene?

Please feel free to send a reproduction project to tony (at) pixelcrushers.com. I can take a look and see if I can figure out why it's doing this.
kilfeather94
Posts: 17
Joined: Sat Jan 23, 2016 1:35 pm

Re: Loading game from Main Menu

Post by kilfeather94 »

Hi Tony,

Sorry for the late response. I've sent you an email, along with a backup project.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Loading game from Main Menu

Post by Tony Li »

I've been working offline with kilfeather94, but I thought it might be helpful to other readers to share my general recommendations here. This is just one approach to handling multi-scene games, but it's worked well for many projects.

Most games have one or more "manager" GameObjects. Often, these GameObjects need to persist across scene loads. The Dialogue Manager is a good example. It's a Singleton, meaning it ensures that one and only one copy exists in the active scene. You can derive your own Singleton MonoBehaviours from the Singleton class on the Unity Community Wiki.

Typically you'll put your managers in a "setup" scene such as a main menu scene. When the player switches from the main menu scene to a gameplay scene, the managers (and all their active data) will come along for the ride.

The problem is that I'm lazy and impatient. :-) I want to be able to playtest any scene directly in the Unity editor without having to come in from a setup scene. To do this, I add the manager objects to each gameplay scene, too. When I run the gameplay scene directly, these managers take effect. However, when I come in from the setup scene, the setup scene's managers persist and destroy the gameplay scene's managers, ensuring that there's only one version of each manager. Make the managers into prefabs so you can make changes to the prefab and have it automatically update all instances in all scenes.

I don't normally treat the player GameObject as a manager. Instead, each scene has a local instance of the player. This tends to work better with most third party player controllers such as UFPS and Realistic FPS Prefab. If you add a Level Manager component to the Dialogue Manager and use one of the Dialogue System's level changing methods (e.g., LevelManager.LoadLevel or the LoadLevel() sequencer command), the Dialogue System will automatically record and apply player information to the local player instance when changing scenes.
Post Reply