Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to save games on mobile(both iOS and Android), works fine in editor. #2

Closed
Nicoconot opened this issue Jul 18, 2022 · 4 comments

Comments

@Nicoconot
Copy link

Hello! I'm not sure if this is a bug related to this save system, but I have a system in place for saving the objects in my scene to different save files according to your profile. At the base, I'm using the Into the Dev save system. It works perfectly in the editor, and not at all on mobile. It seems like it doesn't really manage to save files. Below I'll write down the important parts of the code, and then what I've tried so far and how it's worked out.

Firstly, I've modified a bit the "DataSerializer" script, so as to write the names of saves always with two digits(Save00, Save01, etc), to make loading easier.

public static void ChangeProfile(int profileIndex)
        {
            if (_currentProfileIndex == profileIndex)
                return;
 
            if (profileIndex < 10) filePathModifier = "_0";
            else filePathModifier = "_";
 
            SaveFile();
 
            _currentProfileIndex = profileIndex;
 
         
 
            GeneratePath();
            LoadFile();
        }

private static void GeneratePath() => _savePath = Path.Combine(Application.persistentDataPath, $"{FILE_NAME}" + filePathModifier + $"{_currentProfileIndex}.data");
Basically I just modify the path name a little bit according to our current save profile.

Below are the saving and loading scripts I use, stripped down a bit to make them more readable:

public void SaveAllPOIs()
    {
        GameManager.savedPOIs.Clear();
        foreach (POI poi in addedPOIs)
        {
            GameManager.savedPOIs.Insert(poi.index, poi);          
        }
        DataSerializer.Save("POI_List", GameManager.savedPOIs);
 
        GameManager.localizationManager.SendMessageToConsole("console_sauv_OK");
    }

void Start()
    {      
        if (DataSerializer.TryLoad("POI_List", out List<POI> poilist))
        {
            for (int i = 0; i < poilist.Count; i++)
            {
                AddPOIOnLocation(poilist[i].location, poilist[i]);
            }                      
        }          
    }

public void AddPOIOnLocation(Vector2d location, POI poivar)
    {
        var instance = Instantiate(spawner._markerPrefab, markerParent.transform);
        instance.name = "Marker" + (addedPOIs.Count + 1);
        instance.transform.localPosition = _map.GeoToWorldPosition(location, true);
        instance.transform.localScale = [new](http://www.google.com/search?q=new+msdn.microsoft.com) Vector3(spawner._spawnScale, spawner._spawnScale, spawner._spawnScale);
 
        poivar.marker = instance;
 
        //Spawner variables
 
        spawner.IncreaseMarkers(instance);
        spawner.IncreaseLocations(poivar.location);      
 
        addedPOIs.Add(poivar);
 
        DrawConnections();
        LabelMagic();
    }

This is inside the same file as the above, if that matters:

[System.Serializable]
public class POI
{
    public int index;
    public GameObject marker;
    public Vector2d location;
}

As I said, everything works perfectly fine in the editor(I can't test in a Windows build because I don't have a system to check for geolocalization on desktop computers, which breaks the game in that case. I use the Mapbox SDK by the way). I've had some pointers, which all lead to a dead end:

  • I thought it was a read/write issue on mobile. For Android, I've tried manually adding storage permissions on the manifest, as well as allowing External Sotrage in the player settings. Then I've tried accessing different folders other than the persistent data path, which worked. I just couldn't save.

The very same thing happens on iOs, as wel as several annoying errors on compilation.

  • "Cannot initialize a parameter of type ‘id _Nonnull’ with an rvalue of type ‘Class’". If I remember correctly, this stopped the build from finishing. I've followed the instructions here and it worked.

  • "MissingMethodException: Default constructor not found for type ToolBox.Serialization.OdinSerializer.Int32Serializer". This one I believe came up when trying to save. For this I added public Int32Serializer() : base() {} at the beginning of the script and it worked.

  • "AOT formatter support was missing for type ‘System.Collections.Generic.List’". This error showed up when I clicked on the save button. Now, this pointed me in another direction. I thought the problem might be AOT code stripping. So I've tried disabling code stripping altogether. Hasn't made a difference on Android, still haven't had the chance to retest on iOS. I've messed around with other build settings on Unity to no avail.

I would appreciate it if anyone had some insight onto what might be happening here. I've wasted wayy too much time already debugging this, so I can't really just keep testing different builds on different platforms while putting the project on hold. Please let me know if any information is missing.

Unity Version: 2020.3.33f1
Development platform: Windows 10, Mac for iOS building.

@IntoTheDev
Copy link
Owner

Can you try messagepack branch of this repository? I'll deprecate Odin Serializer version later this summer. Last time I checked il2cpp android build with odin serializer it was working but I'll test both version again today or tomorrow

@IntoTheDev
Copy link
Owner

IntoTheDev commented Jul 18, 2022

I made Mono and IL2CPP builds. Mono build worked perfectly and IL2CPP didn't work at all. I've found the issue. Odin Serializer in my repository was outdated and had some internal AOT generation errors on some Unity versions that was fixed in newer versions of Odin Serializer. I've updated and released new version of my save system. It fixed my IL2CPP build. Please download new version and let me know if it fixed your issue.

Also. Did you create class with implemented ITypeProvider?

Example for your concrete case:

public class DefaultTypeProvider : ITypeProvider
{
    public Type[] GetTypes()
    {
        return new[]
        {
            typeof(POI),
            typeof(Vector2),
        };
    }
}

My messagepack version doesn't need that, it'll do everything for you automatically but that branch isn't fully tested.

TLDR: Download new release and make sure that you've made class with ITypeProvider implemented and your saveable types specified.

@Nicoconot
Copy link
Author

Nicoconot commented Jul 18, 2022 via email

@Nicoconot
Copy link
Author

Aaaand that was it. Thank you so much for your time. I'll still test the messagepack branch whenever I have the chance and report back, but updating and adding the type provider did the trick!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants