Works fine in editor but isn't working in build

Discussion and help for Easy Save 3
Post Reply
Amey
Posts: 5
Joined: Wed Jun 02, 2021 2:05 pm

Works fine in editor but isn't working in build

Post by Amey »

Hi there,

I've been using easy save 3 in project to save load gameobject (with children) and it works fine in editor but not in build. Also the gameobjects I've been saving and loading are a mix of custom made pieces and some unity default shapes (Cube). In the build only the unity default shapes are being loaded and not the custom made pieces. I've enabled the read/write on their model.

I also read a similar post on this forum and it said to use:
1. Persistent data path instead of data path to save/load.
2. While saving/loading in code pass the persistent data path as a parameter in ES3.Save() and ES3.Load() functions.

I changed my settings and code accordingly and it still isn't working. The code of save system is below. Thanks in advance!

Code: Select all

using System.Collections.Generic;
using UnityEngine;

public class TrackSaveSystem : MonoBehaviour
{
    [SerializeField]List<string> savedTrackKeys = new List<string>();

    string path;

    private void Awake()
    {
        path = Application.persistentDataPath + "/SaveFile.es3";
    }

    public void SaveTrack(GameObject trackGO, string trackKey)
    {
        ES3.Save(trackKey, trackGO, path);
        if(trackKey != References.savedTestTrackKey)
            UpdateSavedTrackKeysList(trackKey, true);
    }

    public GameObject LoadTrack(Transform trackStartPOS, string trackKey)
    {
        GameObject LoadedTrackParent;
        LoadedTrackParent = ES3.Load<GameObject>(trackKey, path);
        LoadedTrackParent.transform.parent = trackStartPOS.transform;
        return LoadedTrackParent;
    }

    public void DeleteTrack(string trackKey)
    {
        ES3.DeleteKey(trackKey);
        UpdateSavedTrackKeysList(trackKey, false);
    }

    public List<string> ListOfAllSavedTracks()
    {
        if (ES3.KeyExists(References.savedTrackKeysKey))
            return (List<string>)ES3.Load(References.savedTrackKeysKey,path);
        else
            return null;
    }

    public void ChangeES3TrackGO(GameObject trackGO, string trackKey)
    {
        ES3.Save(trackKey, trackGO,path);
    }

    void UpdateSavedTrackKeysList(string trackKey, bool addingTrack)
    {
        if(ES3.KeyExists(References.savedTrackKeysKey, path))
            savedTrackKeys = (List<string>)ES3.Load(References.savedTrackKeysKey, path);
        
        if (addingTrack)
            savedTrackKeys.Add(trackKey);
        else
            savedTrackKeys.Remove(trackKey);

        ES3.Save(References.savedTrackKeysKey, savedTrackKeys, path);
    }
}
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Works fine in editor but isn't working in build

Post by Joel »

Hi there,

Easy Save uses the persistent data path by default, so you don't need to manually set the path.

Also in your code you only appear to be providing the path to some methods, not others. For example, your ES3.DeleteKey and ES3.KeyExists calls don't appear to have the path set.

I also recommend deleting any existing save data by going to Tools > Easy Save 3 > Clear Persistent Data Path as see if this replicates the issue in the Editor.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Amey
Posts: 5
Joined: Wed Jun 02, 2021 2:05 pm

Re: Works fine in editor but isn't working in build

Post by Amey »

Hi Joel,

My apologies for not being clear that I was using prefabs which had to be referenced to easy save by just right clicking on the prefab. I didn't do that because I thought it was to be done through the inspector window as it was clickable there. Still it was my fault for not reading about saving prefabs beforehand.

Anyways I got it working now and thanks for the quick replies. Much appreciated! :D
Last edited by Amey on Fri Jul 09, 2021 2:47 pm, edited 1 time in total.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Works fine in editor but isn't working in build

Post by Joel »

Hi there,

Please could you replicate this in a new, empty project with a basic scene and private message it to me with instructions? I don't appear to be able to replicate this at my end.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Amey
Posts: 5
Joined: Wed Jun 02, 2021 2:05 pm

Re: Works fine in editor but isn't working in build

Post by Amey »

Hi Joel,

My apologies for not being clear that I was using prefabs which had to be referenced to easy save by just right clicking on the prefab. I didn't do that because I thought it was to be done through the inspector window as it was clickable there. Still it was my fault for not reading about saving prefabs beforehand.

Anyways I got it working now and thanks for the quick replies. Much appreciated! :D
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Works fine in editor but isn't working in build

Post by Joel »

Glad it's working for you now :)

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply