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

Save Scale

Post by Fearinhell »

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
User avatar
Tony Li
Posts: 22137
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save Scale

Post by Tony Li »

Hi,

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);
        }
    }
}
More info (for other readers): How To: Write Custom Savers
Fearinhell
Posts: 44
Joined: Sun Feb 20, 2022 5:53 pm

Re: Save Scale

Post by Fearinhell »

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?
User avatar
Tony Li
Posts: 22137
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save Scale

Post by Tony Li »

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".
Fearinhell
Posts: 44
Joined: Sun Feb 20, 2022 5:53 pm

Re: Save Scale

Post by Fearinhell »

Ahhh I didnt understand that, thank you!
User avatar
Tony Li
Posts: 22137
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save Scale

Post by Tony Li »

Glad to help!
Fearinhell
Posts: 44
Joined: Sun Feb 20, 2022 5:53 pm

Re: Save Scale

Post by Fearinhell »

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
User avatar
Tony Li
Posts: 22137
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save Scale

Post by Tony Li »

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.
Fearinhell
Posts: 44
Joined: Sun Feb 20, 2022 5:53 pm

Re: Save Scale

Post by Fearinhell »

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.
User avatar
Tony Li
Posts: 22137
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save Scale

Post by Tony Li »

Is it a yellow warning or a red error?

Have you added the scenes to your project's build settings?
Post Reply