Enum Data not recording correctly

Discussion and help for Easy Save 3
Post Reply
Fezza
Posts: 4
Joined: Mon Mar 21, 2022 12:21 pm

Enum Data not recording correctly

Post by Fezza »

Hello there!

I was testing out Easy save with my weapon system which uses this form of weapon checking

Code: Select all

namespace PlayerLoadoutSwitch{

    public enum primary{mp5 = 0, akTac = 1, skorpion = 3};
    public enum secondary{fiveseven = 0};
    public enum lethal{grenade = 0};
    public enum tactical{flashbang = 0};

    public enum activeWeapon{mp5 = 0, aktac = 1, skorpion = 2, fiveseven = 3, grenade = 4, flashbang = 5};
    
    
        [Header("Current Weapons")]
        [SerializeField] private primary playersPrimary;
        [SerializeField] private secondary playersSecondary;
        [SerializeField] private lethal playersLethal;
        [SerializeField] private tactical playersTactical;
    
    
     [Header("Selected Weapon")]
     public activeWeapon playersActiveWeapon;
NOTE: This is just a snippet, the rest i do not believe is important as its just the shooting of the weapon etc. if you guys think you need more let me know :D
What really matters here is the active weapon, that is all im trying to change between loads & saves


This is then my DataManager

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PlayerLoadoutSwitch;

public class ManagerScript : MonoBehaviour
{
    [Header("Current Position")]

    [Header("Current Head")]

    [Header("Objective Completed")]

    [Header("Current Weapon & Loadout")]
    public WeaponSwitching_Manager awR;
    public activeWeapon aw;
    [Header("Player Ammo Bag")]
    public Weapon_Ammo playerAmmoBag;
    [Header("Weapons Current Ammo")]
    public MP5_Player mp5;
}
My Save function

Code: Select all

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PlayerLoadoutSwitch;

public class SaveSystem : MonoBehaviour
{
    public ManagerScript ms;

    public void Save()
    {
        ManagerScript script = ms.GetComponent<ManagerScript>();
        ES3.Save("Current Weapon", script.aw);
        ES3.Save("9MM", script.playerAmmoBag.nineMM);
    }
}
& My Load Function

Code: Select all

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PlayerLoadoutSwitch;

public class LoadSystem : MonoBehaviour
{
    public ManagerScript ms;

    public void Load()
    {
        ManagerScript script = ms.GetComponent<ManagerScript>();
        script.aw = ES3.Load<activeWeapon>("Current Weapon");
        Debug.Log("Loading " + script.aw.ToString());
        script.playerAmmoBag.nineMM = ES3.Load<int>("9MM");
    }
}

The issue is that when i save, it creates an enum save path with a value of 0 no matter what enum i saved, even if it was the enum 3 fiveseven. Then when i load, it says everytime it has loaded enum 0 (mp5) only even if i pull out a different weapon then load it says its loading the mp5 yet the wepaon doesnt change!

Any help would be great, if you need more info please lmk
Some of the code might be messy but thats just cause ive been trying other things for it & if it didnt break the compiler i continued, probs a bad habit
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Enum Data not recording correctly

Post by Joel »

Hi there,

I've had no reports of issues of saving and loading enums, and I don't appear to be able to replicate this at my end. Please could you replicate this in a new project with a simple scene and private message it to me with step-by-step instructions.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Fezza
Posts: 4
Joined: Mon Mar 21, 2022 12:21 pm

Re: Enum Data not recording correctly

Post by Fezza »

Thank you for your reply!

I ended up testing in another project with the same code and it didn't work however, after changing a few things it did!

In case for what ever reason someone has the same issue I have attached the code below!

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ManagerScript : MonoBehaviour
{
    [Header("Current Position")]

    [Header("Current Head")]

    [Header("Objective Completed")]

    [Header("Current Weapon & Loadout")]
    public WeaponSwitching_Manager awR;
    [Header("Player Ammo Bag")]
    public Weapon_Ammo playerAmmoBag;
    [Header("Weapons Current Ammo")]
    public MP5_Player mp5;
}

Code: Select all

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SaveSystem : MonoBehaviour
{
    public ManagerScript ms;

    public void Save()
    {
        ManagerScript script = ms.GetComponent<ManagerScript>();
        ES3.Save("Current Weapon", script.awR.playersActiveWeapon);
        ES3.Save("9MM", script.playerAmmoBag.nineMM);
    }
}

Code: Select all

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LoadSystem : MonoBehaviour
{
    public ManagerScript ms;

    public void Load()
    {
        ManagerScript script = ms.GetComponent<ManagerScript>();
        script.awR.playersActiveWeapon = ES3.Load<activeWeapon>("Current Weapon");
        Debug.Log("Loading " + script.awR.playersActiveWeapon.ToString());
        script.playerAmmoBag.nineMM = ES3.Load<int>("9MM");
    }
}

The reason is that i was saving the activeWepaon enum, not the players active weapon so it was always going to be the initial one MP5. With this code, i grab a direct reference to the playersActive Weapon and then save that. I do not need to reference activeWeapon except for the load format.


Thank you!
Post Reply