Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Saving an Array to File

Discussion in 'Editor & General Support' started by MadboyJames, Oct 10, 2019.

  1. MadboyJames

    MadboyJames

    Joined:
    Oct 28, 2017
    Posts:
    262
    I have been working on a map editor for my game, where I can save map presets (maps are tile based for an RTS like StarCrafts or They Are Billions). Currently I save via
    Code (CSharp):
    1. string destination = Application.persistentDataPath + "/"+mapName+"map.dat";
    2.             FileStream file;
    3.  
    4.             if (File.Exists(destination)) file = File.OpenWrite(destination);
    5.             else file = File.Create(destination);
    6.  
    7.             MapSaveData mapSaveData = new MapSaveData(mapLength, mapWidth, bottomLeftCorner.x,bottomLeftCorner.y, bottomLeftCorner.z, tileArray);
    8.             BinaryFormatter bf = new BinaryFormatter();
    9.             bf.Serialize(file, mapSaveData);
    10.             file.Close();
    11.  
    12.             Debug.Log("Map Saved");
    But this seems to mix up my tileArray when the map is loaded at runtime. Does anyone know an approach to do this? This is my first attempt at any sort of unity editor tool and am rather lost.

    any help is appreciated!
     
  2. MadboyJames

    MadboyJames

    Joined:
    Oct 28, 2017
    Posts:
    262
  3. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please provide the specific condition that you are referring to, and the results of your debugging and the code you are using to load it. "Seems to" isn't a lot to go on, please be specific with your actual results vs expected results.