UIS save system and position saver

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
qest43
Posts: 33
Joined: Thu May 26, 2022 9:22 am

UIS save system and position saver

Post by qest43 »

Untitled.png
Untitled.png (14.13 KiB) Viewed 850 times
So I have levels on different scenes. In every scene I had player prefab placed. When scene was loaded, position saver were loading player last position, and move it there, so on the start of every level, there were camera movement visible, from starting point to the loaded point, after fade out. I tried to change it a little and I deleted all player prefabs from scene, and added this code:

Code: Select all

        

            var savedGameData = SaveSystem.storer.RetrieveSavedGameData(GameManager.Instance.currentSaveSlot);
            var s = savedGameData.GetData("playerPositionKey");
            if (!string.IsNullOrEmpty(s))
            {
                var positionData = SaveSystem.Deserialize<PositionSaver.PositionData>(s);
                Instantiate(m_playerPref, positionData.position, Quaternion.identity);
            }
            else
            {
                var position = GameObject.FindGameObjectWithTag("SpawnPoint").transform.position;
                Instantiate(m_playerPref, position, Quaternion.identity);
            }
        
So if there is no any save on current save slot, player will be spawned in gameObject position with SpawnPoint tag. If there is a save on saveslot, player will be spawned on last saved position. This way I avoided this camera movement.

The problem still existed when I was using Pixel Crusher portal. So I added this code to this above:

Code: Select all

if (SaveSystem.playerSpawnpoint != null)
        {
            Instantiate(m_playerPref, SaveSystem.playerSpawnpoint.transform.position, Quaternion.identity);
        }
But I noticed player is instantiated before SaveSystem assign spawnPoint to variable. I have no idea how to solve that.
User avatar
Tony Li
Posts: 21959
Joined: Thu Jul 18, 2013 1:27 pm

Re: UIS save system and position saver

Post by Tony Li »

Hi,

You can use the scene transition manager to fade from black when entering a new scene, which prevents the player from seeing the camera move into place.
qest43
Posts: 33
Joined: Thu May 26, 2022 9:22 am

Re: UIS save system and position saver

Post by qest43 »

it doesn't help, I use it already, and it moves player after fade out. Even when I set a long fade out duration.
User avatar
Tony Li
Posts: 21959
Joined: Thu Jul 18, 2013 1:27 pm

Re: UIS save system and position saver

Post by Tony Li »

Do you have a fade in? It's configured on the Standard Scene Transition Manager's Enter Scene section. Also set the Save System component's Frames To Wait Before Apply Data to 0 or 1.
qest43
Posts: 33
Joined: Thu May 26, 2022 9:22 am

Re: UIS save system and position saver

Post by qest43 »

Untitled.png
Untitled.png (40.96 KiB) Viewed 824 times
Yes, and also it happens when I set frames to wait before in save system component to 0 or 1.
User avatar
Tony Li
Posts: 21959
Joined: Thu Jul 18, 2013 1:27 pm

Re: UIS save system and position saver

Post by Tony Li »

Does this happen in the example scene?

If not, can you send a reproduction project to tony (at) pixelcrushers.com?
User avatar
Tony Li
Posts: 21959
Joined: Thu Jul 18, 2013 1:27 pm

Re: UIS save system and position saver

Post by Tony Li »

Thanks for sending the repro project.

Add this code to the end of the PositionSaver's ApplyData() method:

Code: Select all

if (usePlayerSpawnpoint)
{
    var cameraPos = new Vector3(transform.position.x, transform.position.y, Camera.main.transform.position.z);
    Camera.main.transform.position = cameraPos;
    var vcam = FindObjectOfType<Cinemachine.CinemachineVirtualCamera>();
    vcam.PreviousStateIsValid = false;
}

Or, better yet, make a subclass of PositionSaver and use it for the player:

Code: Select all

public override void ApplyData(string s)
{
    base.ApplyData(s);
    var cameraPos = new Vector3(transform.position.x, transform.position.y, Camera.main.transform.position.z);
    Camera.main.transform.position = cameraPos;
    var vcam = FindObjectOfType<Cinemachine.CinemachineVirtualCamera>();
    vcam.PreviousStateIsValid = false;
}
Post Reply