Save Scale

Announcements, support questions, and discussion for Save System for Opsive Character Controllers.
Fearinhell
Posts: 44
Joined: Sun Feb 20, 2022 5:53 pm

Re: Save Scale

Post by Fearinhell »

Yeah I think I understand all of it except this one part Im confused on. Maybe Im needing to create a variable that gets saved to do this. Basically my game right now has 5 scenes. House, PoliceStatione, Lab, Grocery, Club. How do I know what scenename to put in PixelCrushers.SaveSystem.LoadScene("scene-name"); ? If the player saves in Lab how do I get this coded? Then they save in Grocery. I need a way to save the scenename and call it back. Thanks again! I almost have this working.
User avatar
Tony Li
Posts: 20705
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save Scale

Post by Tony Li »

Is your question about saving and loading games? Or about changing scenes during play?

If your question is about saving and loading games, you don't need to worry about the scene name. As long as the Save System component's "Save Current Scene" checkbox is ticked, the saved game data will contain the scene name, and SaveSystem.LoadFromSlot(0) will load that scene. (However, if you want to load the scene using your own scene loader instead of the Save System, that will require additional work.)

If your question is about changing scenes during play, do you want to use the Save System to change scenes (e.g., using SaveSystem.LoadScene("scene-name")) or use your own scene loader? If you want to use the Save System, the easiest way is to drop a Scene Portal component into the scene at the door. For example, say the PoliceStation has a door to the Lab. You can put a Scene Portal at the PoliceStation's door, and set its scene name to Lab.
Fearinhell
Posts: 44
Joined: Sun Feb 20, 2022 5:53 pm

Re: Save Scale

Post by Fearinhell »

Then I have something else wrong. I am currently using
PixelCrushers.SaveSystem.SaveToSlot(0);

and
PixelCrushers.SaveSystem.LoadFromSlot(0);

for loading and it does the scale saver and doors and some outfits I have added but it doesnt load the correct scene. Im pretty certain I have the scene save still checked. Ill have to go through and see if there is a copy of the save system and that doesnt have that checked or something else. Thanks again.
User avatar
Tony Li
Posts: 20705
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save Scale

Post by Tony Li »

Two things to note:

1. If you use a Save System feature such as PixelCrushers.SaveSystem.LoadFromSlot(0) in code, and if the scene does not have a Save System component, the Save System will create a new, empty GameObject with a default Save System component.

2. The first Save System component to come into existence during play will set its GameObject to DontDestroyOnLoad. If any other Save System components appear after that (for example, in a subsequently-loaded scene), the original Save System will destroy that subsequent Save System's GameObject.
Fearinhell
Posts: 44
Joined: Sun Feb 20, 2022 5:53 pm

Re: Save Scale

Post by Fearinhell »

Hmmm its pretty fool proof then LOL. Ill have to do some looking next week and see. I wont have time til then and Im stumped for ideas.
User avatar
Tony Li
Posts: 20705
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save Scale

Post by Tony Li »

If you're still stumped after looking into it next week, please feel free to send a reproduction project to tony (at) pixelcrushers.com
Fearinhell
Posts: 44
Joined: Sun Feb 20, 2022 5:53 pm

Re: Save Scale

Post by Fearinhell »

Ok I went over and found some things, I think, that I had done wrong. Now I am at least getting an error with the Json Data serializer. Here it is,

ArgumentException: JSON must represent an object type.
UnityEngine.JsonUtility.FromJsonOverwrite (System.String json, System.Object objectToOverwrite) (at <e78722ef08464ab79a3acef56ee8f2b2>:0)
PixelCrushers.JsonDataSerializer.Deserialize[T] (System.String s, T data) (at Assets/Plugins/Pixel Crushers/Common/Scripts/Save System/Serializers/JsonDataSerializer.cs:44)
PixelCrushers.SaveSystem.Deserialize[T] (System.String s, T data) (at Assets/Plugins/Pixel Crushers/Common/Scripts/Save System/SaveSystem.cs:976)
PixelCrushers.MultiActiveSaver.ApplyData (System.String s) (at Assets/Plugins/Pixel Crushers/Common/Scripts/Save System/Savers/MultiActiveSaver.cs:55)
PixelCrushers.SaveSystem.ApplySavedGameData (PixelCrushers.SavedGameData savedGameData) (at Assets/Plugins/Pixel Crushers/Common/Scripts/Save System/SaveSystem.cs:710)
UnityEngine.Debug:LogException(Exception)
PixelCrushers.SaveSystem:ApplySavedGameData(SavedGameData) (at Assets/Plugins/Pixel Crushers/Common/Scripts/Save System/SaveSystem.cs:715)
PixelCrushers.<LoadSceneCoroutine>d__120:MoveNext() (at Assets/Plugins/Pixel Crushers/Common/Scripts/Save System/SaveSystem.cs:839)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

What am I missing Tony?
User avatar
Tony Li
Posts: 20705
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save Scale

Post by Tony Li »

Hi,

It's probably one of these two:

1. You're using the same Key value for a MultiActiveSaver and some other saver component (e.g., your custom saver). Note: If you leave the Key field blank, it will use the GameObject name for the Key. This means if two savers have blank Keys on the same GameObject, they'll use the same Key and overwrite each other's data.

2. Or you modified MultiActiveSaver. If so, I recommend using the original MultiActiveSaver and making your own saver class or a subclass of MultiActiveSaver.
Fearinhell
Posts: 44
Joined: Sun Feb 20, 2022 5:53 pm

Re: Save Scale

Post by Fearinhell »

I still get the above error when I attempt to save in my scene 2. Ill keep going through whats in scene 2 causing this issue. BUT when I save in scene one my position and the scale gets saved but my doors are still not saving their original positions. I also get this error


NullReferenceException: Object reference not set to an instance of an object
PixelCrushers.DialogueSystem.PersistentDataManager.EnsureQuestsExist (System.String saveData) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Save System/PersistentDataManager.cs:351)
PixelCrushers.DialogueSystem.PersistentDataManager.ApplyLuaInternal (System.String saveData, System.Boolean allowExceptions) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Save System/PersistentDataManager.cs:260)
PixelCrushers.DialogueSystem.PersistentDataManager.ApplySaveData (System.String saveData, PixelCrushers.DialogueSystem.DatabaseResetOptions databaseResetOptions) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Save System/PersistentDataManager.cs:246)
PixelCrushers.DialogueSystem.DialogueSystemSaver.ApplyData (System.String data) (at Assets/Plugins/Pixel Crushers/Dialogue System/Scripts/Save System/DialogueSystemSaver.cs:87)
PixelCrushers.SaveSystem.ApplySavedGameData (PixelCrushers.SavedGameData savedGameData) (at Assets/Plugins/Pixel Crushers/Common/Scripts/Save System/SaveSystem.cs:710)
UnityEngine.Debug:LogException(Exception)
PixelCrushers.SaveSystem:ApplySavedGameData(SavedGameData) (at Assets/Plugins/Pixel Crushers/Common/Scripts/Save System/SaveSystem.cs:715)
PixelCrushers.SaveSystem:ApplySavedGameData() (at Assets/Plugins/Pixel Crushers/Common/Scripts/Save System/SaveSystem.cs:744)
MainMenu:LoadGame() (at Assets/Scripts/MainMenu.cs:50)
UnityEngine.EventSystems.EventSystem:Update() (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:501)
User avatar
Tony Li
Posts: 20705
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save Scale

Post by Tony Li »

Hi,

This error will happen if your scene doesn't have a Dialogue Manager GameObject.
Post Reply