ES3's ScriptableObject != ScriptableObject

Discussion and help for Easy Save 3
Post Reply
NamekoEnoki
Posts: 6
Joined: Sun May 24, 2020 9:27 am

ES3's ScriptableObject != ScriptableObject

Post by NamekoEnoki »

Hello. I am not good at English, so I am writing this sentence using Google Translate.
It's hard to read, but I'd appreciate it if you could reply.

I am trying to save a ScriptableObject using EasySave3, but the saved ScriptableObject and the ScriptableObject loaded by Resources.Load are judged to be different.

Also, the prefab that was attached to the ScriptableObject will be removed.

How can I resolve this issue?

Thank you.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: ES3's ScriptableObject != ScriptableObject

Post by Joel »

Hi there,

Please could you show me the code you are using to save and load, and the ScriptableObject you are trying to save?

Note that the ScriptableObject you load will have a different reference because it will be saved by reference and value.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
NamekoEnoki
Posts: 6
Joined: Sun May 24, 2020 9:27 am

Re: ES3's ScriptableObject != ScriptableObject

Post by NamekoEnoki »

Code: Select all

public class SaveTestSM : MonoBehaviour
{
    public SkillData skillData;

    private void Start()
    {
        
    }

    public void SOAttach()
    {
        var skillData = Resources.Load<SkillData>("Skill/ArcticBreath/ArcticBreath");
        this.skillData = skillData;
    }

    public void SOSave()
    {
        ES3.Save("ScriptableObject", skillData);
    }

    public void SOLoad()
    {
        skillData = ES3.Load<SkillData>("ScriptableObject");
    }

    public void SODebug()
    {
        Debug.Log("skillData = " + skillData);
        if (skillData != null)
        {
            Debug.Log("skillData.name = " + this.skillData.name);
            Debug.Log("point0 = " + this.skillData.descriptionPoints[0].points[0]);
            Debug.Log("prefab = " + this.skillData.skillPerformancePrefab);
            var skillData = Resources.Load<SkillData>("Skill/ArcticBreath/ArcticBreath");
            if (this.skillData == skillData)
            {
                Debug.Log("一緒");
            }
            else
            {
                Debug.Log("違う");
            }
            var skillPerformance = Instantiate(this.skillData.skillPerformancePrefab).GetComponent<SkillPerformance>();
            Debug.Log("skillPerformance = " + skillPerformance);
        }

    }

}



[CreateAssetMenu(fileName = "NewSkill", menuName = "UDB/Skill/Data")]
[System.Serializable]
public class SkillData : ScriptableObject
{

    public new string name;
    public Sprite icon;
    public Rarity rarity;
    [Multiline(10)]
    public string description;

    [SerializeField]
    public List<DescriptionPoint> descriptionPoints = new List<DescriptionPoint>() { new DescriptionPoint() };

    public float coolTime = 5f;
    public float globalDelay = 1;

    public GameObject skillPerformancePrefab;

    [System.Serializable]
    public class DescriptionPoint
    {
        public Keyword keyword;

        [HorizontalGroup]
        public PointType pointType;

        [HorizontalGroup]
        [ListDrawerSettings(Expanded = true)]
        public float[] points = new float[1];

        public string text;

        public float GetCalcedPoint(Battler battler = null, int pointId = 0)
        {
            if (battler == null) battler = BattleDB.Instance.ally;
            float point = points[pointId];
            if (pointType == PointType.Fixed)
            {

            }
            else if (pointType == PointType.Hp)
            {
                var maxHp = battler.maxHp;
                point *= maxHp;
            }
            else if (pointType == PointType.Atk)
            {
                var calcedAtk = battler.CalcedAtk;
                point *= calcedAtk;
            }
            else
            {
                var calcedDef = battler.CalcedDef;
                point *= calcedDef;
            }
            if(battler is Ally)
            {
                var pointOfKeyword = Map_AllyDB.Instance.GetPointOfKeyword(keyword);
                switch (keyword)
                {
                    case Keyword.Target:
                        point += pointOfKeyword;
                        break;
                    case Keyword.Projectile:
                        point += pointOfKeyword;
                        break;
                    case Keyword.Poison:
                        point *= 1 + pointOfKeyword;
                        break;
                    case Keyword.None:
                        point += pointOfKeyword;
                        break;
                    case Keyword.Lightning:
                        point *= 1 + pointOfKeyword;
                        break;
                    case Keyword.Ice:
                        point *= 1 + pointOfKeyword;
                        break;
                    case Keyword.Fire:
                        point *= 1 + pointOfKeyword;
                        break;
                    case Keyword.Duration:
                        point *= 1 + pointOfKeyword;
                        break;
                    case Keyword.Debuff:
                        point *= 1 + pointOfKeyword;
                        break;
                    case Keyword.Cycle:
                        point *= 1 + pointOfKeyword;
                        break;
                    case Keyword.Chain:
                        point += pointOfKeyword;
                        break;
                    case Keyword.Buff:
                        point *= 1 + pointOfKeyword;
                        break;
                    case Keyword.AOE:
                        point += pointOfKeyword;
                        break;
                }
            }
            return point;
        }
    }

    public enum PointType
    {
        Fixed = 0,
        Hp = 3,
        Atk = 1,
        Def = 2
    }

    public enum Rarity
    {
        Basic,
        Common,
        Uncommon,
        Rare
    }
}
Each method of SaveTestSM is assigned to a UI button to save and load.

When I exit the game, load it again and hit the debug button, the log says "(SkillData)" instead of "SkillName (SkillData)"
It will become.

Furthermore, the prefab will also come off.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: ES3's ScriptableObject != ScriptableObject

Post by Joel »

Hi there,

This is because when you load, it creates an instance of the ScriptableObject.

With regards to the prefab being missing, this is likely because there isn't a direct reference to your prefab in the scene, so the reference manager does not have a reference to it. Try right-clicking the prefab and pressing Easy Save 3 > Add Reference to Manager.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
NamekoEnoki
Posts: 6
Joined: Sun May 24, 2020 9:27 am

Re: ES3's ScriptableObject != ScriptableObject

Post by NamekoEnoki »

Thank you for your reply.

What if I want to compare the loaded skillData with the prepared skillData in if statement etc.?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: ES3's ScriptableObject != ScriptableObject

Post by Joel »

Hi there,

If you do need to save the name for comparison purposes, you can do so by going to Window > Easy Save 3 > Types, search in the name of your ScriptableObject, and check the 'name' property.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
NamekoEnoki
Posts: 6
Joined: Sun May 24, 2020 9:27 am

Re: ES3's ScriptableObject != ScriptableObject

Post by NamekoEnoki »

So that's it!
It was helpful!
Thank you!
Post Reply