Page 1 of 1

Saving/Loading Sprites when SpriteMode is set to Multiple in Import Settings

Posted: Fri Mar 26, 2021 4:59 pm
by Ninin
Hello,

I want to save sprites from my Players spriteRenderer in order to display it later on my Main Menu when the Player resumes the game.
I wrote this class (to regroup data) :

Code: Select all

public enum PlayerCharacter { PLAYER1, PLAYER2, PLAYER3 }
public class MainMenuPlayerInfo
{
    public PlayerCharacter Player;
    public Sprite PlayerSprite;
        public MainMenuPlayerInfo()
    {
        Player = PlayerCharacter.PLAYER1;
        PlayerSprite = null;
    }
        public MainMenuPlayerInfo(PlayerCharacter player, Sprite playerSprite)
    {
        Player = player;
        PlayerSprite = playerSprite;
    }
}
And I use this type of code to save :

Code: Select all

GameObject Player = GameObject.FindWithTag("Player");
 Queue<MainMenuPlayerInfo> playersInfoQueue = new Queue<MainMenuPlayerInfo>();
 playersInfoQueue.Enqueue(new MainMenuPlayerInfo(PlayerCharacter.PLAYER1, Player.GetComponent<SpriteRenderer>().sprite));
 saveFile.Save<Queue<MainMenuPlayerInfo>>("MainMenuPlayerInfoQueue", playersInfoQueue);
And this one to Load :

Code: Select all

Queue<MainMenuPlayerInfo> playersInfos = currentSaveFile.Load<Queue<MainMenuPlayerInfo>>("MainMenuPlayerInfoQueue");
The sprite loads fine when I use it with a sprite with SpriteMode = Single in Asset Import Settings, but when I try with a sprite with SpriteMode = Multiple, the loaded sprite is null and I don't understand why. I also get this warning from EasySave in this last case only :

"Reference for UnityEngine.Sprite with ID 1018448855446032586 could not be found in Easy Save's reference manager. Try pressing the Refresh References button on the ES3ReferenceMgr Component of the Easy Save 3 Manager in your scene. If you are loading objects dynamically, this warning is expected and can be ignored."

I'm using Unity 2019.4.8f1 and Easy Save 3.3.2f1.

Re: Saving/Loading Sprites when SpriteMode is set to Multiple in Import Settings

Posted: Fri Mar 26, 2021 5:08 pm
by Joel
Hi there,

Please could you create a new, basic project with a basic scene which replicates this and private message it to me? I've tried replicating this at my end up don't appear to be encountering issues.

All the best,
Joel

Re: Saving/Loading Sprites when SpriteMode is set to Multiple in Import Settings

Posted: Mon Mar 29, 2021 5:48 pm
by Ninin
Mea culpa it seems it was not due to the SpriteMode but to the fact that the Sprite was not added to the manager prior to Runtime.
I tried either to reference the Sprite in the scene prior to Runtime, or add manually the reference to the manager to each slice of the Sprite Asset (right-clicking on the slices -> Easy Save 3 -> Add Reference To Manager) and it worked in both cases.