Save Scale
-
- Posts: 44
- Joined: Sun Feb 20, 2022 5:53 pm
Save Scale
I am just starting to learn how saving works and am using UCC Saver script with several game objects being saved active/inactive. What I am missing is the ability to save the scale of the character. My game starts with .9 and can end with any size. How can I get this save system to work? I was looking at the custom saver but I need more example code for this. Thanks
Re: Save Scale
Hi,
You could save it like this:
ScaleSaver.cs
More info (for other readers): How To: Write Custom Savers
You could save it like this:
ScaleSaver.cs
Code: Select all
using UnityEngine;
using PixelCrushers;
public class ScaleSaver : Saver
{
public override string RecordData()
{
// Assume X, Y, and Z are all scaled to the same value. Return that value as a string:
return transform.localScale.x.ToString();
}
public override void ApplyData(string s)
{
if (string.IsNullOrEmpty(s)) return; // If we didn't receive any save data, exit immediately.
float scale;
if (float.TryParse(s, out scale))
{
transform.localScale = new Vector3(scale, scale, scale);
}
}
}
-
- Posts: 44
- Joined: Sun Feb 20, 2022 5:53 pm
Re: Save Scale
Thanks Tony!
So I take this code and make a script file and attach it to the player or object I need the scale saved? Does the dialogue system automatically save it then when I run the save system? Does it search for record data string in the code? And yes the scaling stays the same between xyz.
Ok I see that I get a warning that the GameObject has more than one saver component. Can I just add this to the UCCSaver code then?
Would changing the return s close to line 240 in the UCCSaver script to
return s + transform.localScale.x.ToString();
work? Im not for sure if it can return two variables like this?
So I take this code and make a script file and attach it to the player or object I need the scale saved? Does the dialogue system automatically save it then when I run the save system? Does it search for record data string in the code? And yes the scaling stays the same between xyz.
Ok I see that I get a warning that the GameObject has more than one saver component. Can I just add this to the UCCSaver code then?
Would changing the return s close to line 240 in the UCCSaver script to
return s + transform.localScale.x.ToString();
work? Im not for sure if it can return two variables like this?
Re: Save Scale
Hi,
Don't add it to UCC Saver. The warning tells you to assign unique Key values to each saver. Please do that. For example, set the player's UCC Saver key to something like "playerUCC" and the Scale Saver key to "playerScale".
Don't add it to UCC Saver. The warning tells you to assign unique Key values to each saver. Please do that. For example, set the player's UCC Saver key to something like "playerUCC" and the Scale Saver key to "playerScale".
-
- Posts: 44
- Joined: Sun Feb 20, 2022 5:53 pm
Re: Save Scale
Ahhh I didnt understand that, thank you!
-
- Posts: 44
- Joined: Sun Feb 20, 2022 5:53 pm
Re: Save Scale
Tony,
Im missing something here when loading. Im just creating a simple save load, it saves when the player exits and just one slot. They quit the game and then reload the game and try to click continue which is tied to this code
SaveSystem.LoadFromSlot(0);
But nothing happens. Is this because it isnt then loading a scene command? How can I know what scene to load based on their save location? What am I doing wrong? Thanks
Im missing something here when loading. Im just creating a simple save load, it saves when the player exits and just one slot. They quit the game and then reload the game and try to click continue which is tied to this code
SaveSystem.LoadFromSlot(0);
But nothing happens. Is this because it isnt then loading a scene command? How can I know what scene to load based on their save location? What am I doing wrong? Thanks
Re: Save Scale
Hi,
If the Save System component's Save Current Scene checkbox is ticked, it will save the name of the current scene that the player is in. When loading a saved game, it will load that scene.
Is everything else loading properly, such as the player's saved stats and ammo? Or is nothing loading? If nothing is loading, make sure you're loading from the same slot that you saved to.
If the Save System component's Save Current Scene checkbox is ticked, it will save the name of the current scene that the player is in. When loading a saved game, it will load that scene.
Is everything else loading properly, such as the player's saved stats and ammo? Or is nothing loading? If nothing is loading, make sure you're loading from the same slot that you saved to.
-
- Posts: 44
- Joined: Sun Feb 20, 2022 5:53 pm
Re: Save Scale
Hmmmm yeah that check box is checked, and nothing happens in my menu when the above code is called.
My code to save is
SaveSystem.SaveToSlot(0); //Save Game
Ok something I just am figuring out, while running the game through the editor continue works but when I do a build continue doesnt. I have a warning that I dont have an attribute manager or inventory component, but Im not using any of those in my game. Im just saving locations and if doors have been opened. And That all works inside the editor while saving and loading.
My code to save is
SaveSystem.SaveToSlot(0); //Save Game
Ok something I just am figuring out, while running the game through the editor continue works but when I do a build continue doesnt. I have a warning that I dont have an attribute manager or inventory component, but Im not using any of those in my game. Im just saving locations and if doors have been opened. And That all works inside the editor while saving and loading.
Re: Save Scale
Is it a yellow warning or a red error?
Have you added the scenes to your project's build settings?
Have you added the scenes to your project's build settings?