Forum rules - please read before posting.

Remember Transform with Scale

edited February 2022 in Technical Q&A

Hello!

I believe I'm doing something incorrect. I have on my Player character that is Instanced using AC a Remember Transform. Due to how my game is designed, I need to change the scale of the character each new camera position. I use the Object Transform and set the Scale to what I need.

If I save the game and reload it, there is a possibility that the scale doesn't get set correctly. I do not know if it's due to an animation or what.

I am asking if the Remember Transform is supposed to scale Rotate and Scale and if it does, based on loading a saved game, is there anything I should be looking at to see why it's using the Default scale of the Prefab and not what it should have saved?

Thanks!
Unity 2019.4.35f1
AC v1.74.2

Comments

  • edited February 2022

    Is this for a 2D or a 3D character, and are you scaling their root or a child object?

    When working in 2D, the character's scale is saved/loaded internally, as their scale is typically determined by their position in the scene via a Sorting Map.

    Remember Transform will record scale, but it may be that the two data sets are conflicting, and the Player's data is overwriting it.

    If you want to update a character's scale, try using the Character: Change rendering Action, which can be used to set a character's scale - including those in 3D games.

  • edited February 2022

    Chris:

    Yes, it's for 3D character on the root. I literally have over 100 scale changes, it's going to take a while to swap all those out to Character: Change rendering.

    UPDATE:
    I looked into the Character: Change Rendering and my option is New Scale%. I need to be able to enter an exact number, such as 3.6 like I do for Object: Transform Moveable object Scale.

  • Don't go changing every instance just yet. Without seeing your actual character, I'm only making suppositions.

    Does using the Character: Change rendering as it is for the moment at least cause the scale to be correctly changed after reloading?

    Let's see shots of the character's full Inspector. If they don't have a Follow Sorting Map component, then their scale should be unaffected internally, so Remember Transform ought to work.

    It's also possible to make use of custom Remember scripts - try this one, which specifically saves the scale of the object it's attached to:

    using UnityEngine;
    
    namespace AC
    {
    
        public class RememberScale : Remember
        {
    
            public override string SaveData ()
            {
                ScaleData data = new ScaleData();
                data.objectID = constantID;
                data.savePrevented = savePrevented;
    
                data.scale = gameObject.transform.localScale;
    
                return Serializer.SaveScriptData <ScaleData> (data);
            }
    
    
            public override void LoadData (string stringData)
            {
                ScaleData data = Serializer.LoadScriptData <ScaleData> (stringData);
                if (data == null) return;
                SavePrevented = data.savePrevented; if (savePrevented) return;
    
                gameObject.transform.localScale = Vector3.one * data.scale;
            }
    
        }
    
    
        [System.Serializable]
        public class ScaleData : RememberData
        {
    
            public float scale;
    
            public ScaleData () { }
    
        }
    
    }
    
  • Chris:

    Here is a link to the character's full inspector as requested. I am still testing the Character: Change Rendering

    https://photos.app.goo.gl/2o9etfLcC6C1U38PA

    Thanks!

  • Try replacing your Remember Transform script with the Remember Scale one above. You mention instantiating the Player with it, but with Players you should rely on AC's automation of this instead.

    If you need a Player to be spawned into the scene at a specific point, enable Player-switching and use the "Player: Switch" Action.

  • Chris:

    Also fixed your script. Your data.scale is only a float so I picked one of the axis of the localScale since they are all the same.

    data.scale = gameObject.transform.localScale.x;

    Thanks.

  • Chris:

    When I stated instantiating, I was referring to "AC's automation"

    Thanks!

  • Also fixed your script

    And after this, what was the result?

  • edited April 2022

    Chris:

    No, it's still a problem and I can duplicate it 100% of the time.

    I am trying this on PS4, PS5, Nintendo Switch and XBox and it all have the same issues.

    I'm saving the data as a PlayerPrefs so I can see the values. Any suggestion on where I should be looking?

    It seems like it's always saving the default value the player comes in the scene as and not the current value of what the player is at the time of saving. Example, player is set right at the beginning to a scale of 3.5 before any other changes take place, it stays that value. My value of the Prefab is set to 5 so it's not saving that value. I walk around and each camera changes the scale to a different value. No matter what the new scale is, it will always save it as 3.5. The loading position is correct, the rotation is correct, just not the scale.

    Thanks!

  • I can't recreate the issue on my end - attaching the (corrected) RememberScale component to Tin Pot in the 3D demo correctly saves his scale. Did you remove the Remember Transform component as well?

    Try the 3D demo on your end - is it the same for you?

    I'm saving the data as a PlayerPrefs so I can see the values. Any suggestion on where I should be looking?

    It'll be in the "Remember data" section, at the bottom of the Player data part of the Save File Manager.

  • Chris:

    How do I set the saving to be JSON or XML or anything that's not binary? Maybe I can compare save to load and see what's going on.

    Thanks

  • Chris:

    How do I set the saving to be JSON or XML or anything that's not binary? Maybe I can compare save to load and see what's going on.

    Thanks

  • The "Save-game file Manager" presents data in a readable way regardless of format, but if you want to alter the format itself you can do that with:

    SaveSystem.FileFormatHandler = new MyClassName ();
    

    FileFormatHandler_Xml and FileFormatHandler_Json are both valid class names - see the Manual's "Custom save formats and handling" chapter for details.

  • edited April 2022

    Chris:

    I'm think I'm getting closer. I have three different players ( Player 0, Player 1 and Player 3 ). I look at the Player data #0 and the only "Remember data" it has is AC.AnimationData. Am I looking in the correct area?

    https://photos.app.goo.gl/f8bw32rKETxdyhMUA

  • If the "0" is the correct Player ID, then yes - is this the default? How many Remember components are on each of your Players?

    Json-saving can have an issue when it comes to multiple Remember components on a single object if any of them are custom. Switch back to Binary if you weren't already, and try removing all but Remember Scale to see if it then shows after saving.

  • edited April 2022

    Chris:

    I had Remember Animation as well as Remember Scale ( in that order, from top to bottom ). I removed Remember Animation and checked the box in Remember Scale to "Retain in prefab?" and it "seems" to work. More testing is needed.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.