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

[Discontinued] Unity Save Load Utility (Free!) - Save and load your data

Discussion in 'Assets and Asset Store' started by Cherno, Oct 9, 2016.

  1. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    [IMPORTANT]
    I will discontinue support for this asset since it has become clear to me that saving and loading a Unity scene in an all-encompassing way is far too difficult with a free product that requires constant updates and testing as well as support for users (as this thread shows). I will keep the download link since it can still serve as the way it was originally intended, namely a way to show how such a system could be attempted and as a foundation for developers to base their own solution on.

    For my personal future projects, I will probably use a checkpoint-based system where I have full control over the data that is saved, and in which way.
    [/IMPORTANT

    Unity Save Load Utility has been uploaded for everyone! This utility is an evolution of my SerializeHelper utility which has been expanded tremendously.

    Unity Save Load Utility (USLU) is a free solution for adding save and load functionality to your games. Save a whole runtime scene, or just single GameObjects, and decide for yourself exactly which data should be saved, and how.

    Saving and loading player progress is one of the most important features of all but the shortest games. However, there are few free solutions available for developers,and the late and great Unity Serializer is something of a monster in complexity and no longer actively supported. That's why I wrote my own save and load system and I share it with you, the community. You can also use it to save maps you made in your own map editor, and more.

    USLU is written in a simple and well-documented way so beginners can easily understand what's going on and add their own functionality should they need to. It is also a good primer on general data serialization as it explains some advanced topics, like using SerializationSurrogates. The system is relatively simple yet flexible and should provide a solid base that covers most project's needs.

    Not only is the understanding of the inner workings helped by a large number of comment sections, but you also get a HTML manual which explains the general functionality.

    Before you start, I suggest taking a quick glance at both the QuickStart Guide and the Manual which are located in the Readme folder.

    I plan to submit USLU to the Asset Store in the future. Until then, feel free to download it directly from my DropBox.

    Download link:
    USLU Unity package

    USLU Manual (included with asset):
    USLU_Manual.html
    USLU QuickStart Guide (included with asset):
    USLU_QuickStart.html
     
    Last edited: Oct 13, 2020
  2. BoboShu

    BoboShu

    Joined:
    Nov 20, 2014
    Posts:
    38
    really cool !
     
  3. Dexmes

    Dexmes

    Joined:
    Oct 1, 2015
    Posts:
    3
    AWESOME! Great utility and great coder / publisher A++ Cherno
     
  4. takuya951753

    takuya951753

    Joined:
    Oct 14, 2016
    Posts:
    2
    @Cherno
    Hey Cherno :) I looked at your creation, and I must say it's top notch! But I've got a problem.. I'm new to all of this haha
    So I marked all gameobjects I want to save with the ObjectIdentifier Script and put in the Prefab Name. I made Prefabs of all gameobjects in the Resources/Prefabs folder and I made a new gameobject with the Menu script , the Utility script and the Persistence Marker on it. Also all scripts on those gameObjects have [system.serializable]. First I have a question. I want this gameobject to remain in a the game, even if I change scenes. My Player and my Camera for example are "DontDestroyOnLoad" , so they come with you when u walk in a door for example. So should I just make a new script and attach it to this new GameManager object, so it doesn't get destroyed, too?

    Also, when I start the game in my first scene, I can use the menu just fine, but if I press on save, then enter a name for the save-file, when I press save again nothing happens. Not in the game, nor in the inspector. Now, I don't really know why I can't use it. Maybe I just forgot something?

    Sorry, if it's a simple mistake haha, but I'd really be glad if this could be resolved somehow.

    Thanks a lot! :)
     
  5. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    @takuya951753
    Hello and thanks for you message. I will try my best to answer your questions!

    1. Scripts don't need the [System.Serializable] attribute, only non-MonoBehavior classes do (including those that are sub-classes of a script).
    2. If an object shouldn't be destroyed when loading a game, put the PersistenceMarker component on it like you did with the GameObject that has the Menu and Utility scripts.
    3. DontDestroyOnLoad isn't used by USLU, it uses the PersistenceMarker component instead. The reason for this is so the tag functionality of Unity isn't used up by USLU.
    4. About your question regarding the save button in the menu: The menu was added as something of an afterthought and wasn't really meant to be part of the core functionality, it was simply something to get people started quickly so they can try things out. Anyway, I failed to add a failsafe that checks if a savegame path has the correct format, with a slash at the end. If it hasn't got one, then no file will be saved because the directory won't be found. You can quickly resolve this problem by adding a slash "/" to the end of your savegame path. However, I encourage you to download the package again which I have uploaded once more, it contains an updated version of the SaveLoad file which adds this failsafe and ensures that the path has the correct format. Nothing else has changed so you should be fine with just replacing this single file in your project.
     
    theANMATOR2b likes this.
  6. takuya951753

    takuya951753

    Joined:
    Oct 14, 2016
    Posts:
    2
    Thanks a lot for your anwser Cherno! I will try that out! :D
     
  7. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    I have to apologize, I just realized what you meant with the DontDestroyOnLoad function you mentioned. I thought you referred to USLU's predecessor's (SerializeHelper) way of preventing GameObjects from being destroyed when a game is loaded, which was by giving them a special tag. You, however, meant Unity's built-in function that prevents objects from being destroyed when loading a scene. So, please disregard what I wrote about that topic, and keep using DontDestroyOnLoad for scene changes. For loading games, use the PersistenceMarker components.
     
    Sigma266 likes this.
  8. borasko34

    borasko34

    Joined:
    May 14, 2016
    Posts:
    2
    @Cherno

    Cherno, thank you for providing this, I'm having some pretty good success with it so far but being fairly new to Unity and game dev, I had a couple of questions.

    Several of my scripts assign variables in the Start() function, for example:

    Code (CSharp):
    1. private void Start()
    2. {
    3.     player = GameObject.FindGameObjectWithTag ("Player");
    4. }
    I'm having difficulty with loading this information after saving the game. It tells me that the object that the script is trying to reference has been destroyed even if it has been saved and loaded along with everything else. If I put the above script into my Update() function, it works fine but I don't want to cause performance issues with Update() constantly calling FindGameObjectWithTag or GetComponent<>. I tried to use the OnLoad function as shown below but that didn't seem to work for me.

    Code (CSharp):
    1. public void OnLoad()
    2. {
    3.     player = GameObject.FindGameObjectWithTag ("Player");
    4. }
    The other question was if you could help walk me through creating my own Surrogate. I attempted to make my own SpriteSurrogate to save sprites as a lot of the player actions change the sprites of tiles in the game. I created a SpriteSurrogate script in the Surrogates folder, added "Sprite" to the surrogateTypes List in SaveLoadUtility and I added SpriteSurrogate to the AddSurrogates in SaveLoad (code all below). When I try to save the game, Unity throws an error saying "Value is not a convertible object: System.Boolean to UnityEngine.Sprite". If you can let me know where I'm going wrong with this, that would be fantastic. I'm loving this asset and would like to know how to use it more properly. Thanks!

    SpriteSurrogate Code:
    Code (CSharp):
    1. using System.Runtime.Serialization;
    2. using UnityEngine;
    3.  
    4. public class SpriteSurrogate : ISerializationSurrogate {
    5.  
    6.     // Method called to serialize a Sprite object
    7.     public void GetObjectData(System.Object obj,
    8.         SerializationInfo info, StreamingContext context) {
    9.  
    10.         Sprite sprite = (Sprite) obj;
    11.         info.AddValue ("sprite", sprite);
    12.     }
    13.  
    14.     // Method called to deserialize a Sprite object
    15.     public System.Object SetObjectData(System.Object obj,
    16.         SerializationInfo info, StreamingContext context,
    17.         ISurrogateSelector selector) {
    18.  
    19.         Sprite sprite = (Sprite) obj;
    20.         sprite = (Sprite)info.GetValue ("sprite", typeof(Sprite));
    21.         obj = sprite;
    22.         return obj;
    23.     }
    24. }
    SaveLoadUtility Code:
    Code (CSharp):
    1. private Dictionary<RefReconnecter,string> refDict;//used to reconnect fields of Type GameObject and those inheriting from Component to their respective reference instances again after loading.
    2.     [HideInInspector]private List<string> surrogateTypes = new List<string>() {
    3.         "Vector2",
    4.         "Vector3",
    5.         "Vector4",
    6.         "Quaternion",
    7.         "Color",
    8.         "Color32",
    9.         "Sprite"
    10.     };
    SaveLoad Code:
    Code (CSharp):
    1. public static void AddSurrogates(ref SurrogateSelector ss) {
    2.  
    3.         SpriteSurrogate Sprite_SS = new SpriteSurrogate();
    4.         ss.AddSurrogate(typeof(Sprite), new StreamingContext(StreamingContextStates.All), Sprite_SS);
    5. }
     
  9. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    1. After some testing, I'm not sure why the GameObject is displayed as "missing". The GameObject.FindWithTag function works and successfully finds the GameObject that has the Player tag, but for some reason Unity destroys it afterwards even though it shouldn't, yet the GameObject is still there... it's very strange and I couldn't make any sense of it. All I know is that USLU is not responsible. It's some quirk of Unity.
    However, instead of using FindWithTag, you can insert this bit of code into your OnLoad function and it will work:

    Code (CSharp):
    1. foreach(KeyValuePair<string,ObjectIdentifier> pair in SaveLoad.objectIdentifierDict) {
    2.             if(pair.Value.tag == "Player") {
    3.                 player = pair.Value.gameObject;
    4.             }
    5.         }
    You can also start a Coroutine which waits one frame before calling GameObject.FindWithTag.

    2. You added the ISerializationSurrogate correctly to the SurrogateSelector and the surrogates list, but your implementation itself needs work. Your ISS currently is superfluous since it just does what would be done anyway by the BinaryFormatter, which is to take a value and (de)serialize it. However, ISS here are used to convert Types that can't be serialized into a form that can, so what you would need to do is think about what exactly you need to save and load. From your description, I'm not entirely sure what you mean by "player actions change the sprites of tiles in the game". If you could provide more information about how these sprites are changed, and what you want to save and load, I will try to help you with that as well :)
     
    Last edited: Oct 18, 2016
  10. Nogs

    Nogs

    Joined:
    Jul 12, 2016
    Posts:
    2
    Cherno, do you think it would be possible with some refactoring to get this plugin to save to JSON instead of binary? Just wanna know if you think that's feasible before I start hacking on it.
     
    Apio07 likes this.
  11. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    I have zero experience with JSON so I'm not a 100% sure about this, but I don't see why it wouldn't work.
     
  12. heartmann

    heartmann

    Joined:
    Sep 29, 2016
    Posts:
    2
    Fantastic work on this, @Cherno! I've been working on an XML system that does pretty much the same thing, but this is much better than what I've been able to achieve so far (and much faster, of course). Anyway, I was wondering whether changing it to using AssetBundles rather than loading from Resources would be possible? I'm developing an application for VR and Web, and the idea was to use hi-poly models for VR and lo-poly models for the web application, but otherwise have scenes be interchangeable, so that the user can change something online and then go view it in VR (imagine it's like the Sims, where you can build houses). Using AssetBundles it seems I could simply use variants and that'd take care of it, so I was wondering whether I could modify the script to load from an AssetBundle variant instead, depending on the platform—would you happen to have any insight into this? Thanks again for the great product!
     
  13. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    Hello!
    I have zero experience with AssetBundles, but from what I understand the Resources folder is internally treated like just another AB. In the end, it shouldn't matter where the data comes from, it's jsut the syntax that is slightly differerent when actually loading an asset.
    So, from my limited understanding, it should be just a matter of changing the few lines of code at the start that fills the prefab dictionary so it get them from the AB in question.
     
  14. heartmann

    heartmann

    Joined:
    Sep 29, 2016
    Posts:
    2
    Yeah, awesome, that's what I was thinking too. I've started working on it, but as I too am new to AssetBundles, it's proving slightly more time-consuming than I had hoped, but it does seem possible. Thanks for the reply and motivation, though; it's nice to have the creator approve!
     
  15. silverscania

    silverscania

    Joined:
    Apr 4, 2015
    Posts:
    1
    I'm looking into using this now, thanks. As well as putting it on the asset store you could put it on github and we can all contribute.
     
  16. Beastman632

    Beastman632

    Joined:
    Dec 12, 2016
    Posts:
    8
    This is amazing. You did the game developing community a great service, thank you!
     
  17. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    Thank you! I hope it helps developers create better games :)
     
  18. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    Just aquick note to all who have downloaded the package or the manual so far:

    There was a slight error in part 3.5. The titel was "ObjectComponent" which of course makes no sense, it should be "ObjectIdentifer Component". Thisd has been corrected. Thanks to Beastman632!

    The corected manual available for single download as well as the one included in the package has been re-uploaded.
     
  19. Beastman632

    Beastman632

    Joined:
    Dec 12, 2016
    Posts:
    8
    Hey Cherno. Currently I see that a object with the ObjectIdentifier component can't save the transform of a object that doesn't have that component. For example persistent objects. Because what I was trying to do is to pair children that has persistent objects as parents together after a load. Since persistent objects don't have ID's, my solution to this was to save the transform of the parent and then assign it after a load like this:


    Code (CSharp):
    1.  
    2. public Transform parent;
    3.  
    4.     void OnSave()
    5.     {
    6.         parent = transform.parent;
    7.     }
    8.  
    9.     void OnLoad()
    10.     {
    11.         transform.parent = parent;
    12.     }
    Is this because persistent objects are actually clones? So the transform of the object that was suppose to be saved doesn't exist anymore or is your code just set up to not be able to save references to components of persistent objects?
    Thanks in advance
     
  20. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    The parent reference won't be saved because Transform Type fields need an id from an ObjectIdentifier component.
    You could just give the persistent parent a unique name and then save that name as a string in new variable in OnSave, and in OnLoad search for that naem via GameObject.Find. Alternatively, you could generate a uniqe id with GUID by copying the relevant code form the ObjectIdentifier script and store it in a variable in any of the persistent paren't script, then in OnLoad search for all occurances of the script you saved it in, and re-parent the child.
     
  21. Beastman632

    Beastman632

    Joined:
    Dec 12, 2016
    Posts:
    8
    Okay so have written a little script, that is partly based on the ObjectIdentfier scripts (PairObject.cs), that is able to pair ObjectsIdentifier objects with persistent objects as well as pair them with the children of other ObjectsIdentifier objects. For example Parent(ObjectIdentifier) > Child(Part of prefab) > Child(ObjectIdentifier). Meaning if you have a prefab that has children, those children won't have the ObjectIdentifier component, since the parent already has it. So the problem I encountered was that I couldn't pair ObjectIdentifer objects with the children of other ObjectIdentifier Objects. So this is now solved. I made a small modification to the persistenceMarker scripts by adding the ID like you suggested.

    The persistent parent's ID is not saved because it does not have the objectIdentifier component. So when a game is loaded without having saved it first after runtime, the persistent parent won't have the same ID as before, thus making pairing impossible. To solve this I serialized its ID. So the persistent object will now always have the same ID on any savegame state
     

    Attached Files:

    Last edited: Dec 18, 2016
    Cherno likes this.
  22. kMak

    kMak

    Joined:
    Aug 5, 2013
    Posts:
    11
    Thanks for this plugin Cherno! I'm just getting started on figuring out how to implement it into my app. Does it work for mobile devices?
     
  23. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    I didn't test it on mobile devices.
     
  24. kMak

    kMak

    Joined:
    Aug 5, 2013
    Posts:
    11
    Ah, gotcha. Do you think it should work theoretically? My application is purely on mobile devices so I was wondering if it's worth investing my time.
     
  25. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    I have no experience with developing for mobile devices so I can't give you any qualified answer :)
     
  26. kMak

    kMak

    Joined:
    Aug 5, 2013
    Posts:
    11
    No worries, thanks for the response!
     
  27. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    I noticed that dictionaries that take two non-System Types as key and value won't be read properly. Also, Reference Types are not reconnected after loading. These are the two things I'm trying to fix right now.
     
    Beastman632 likes this.
  28. Ginxx009

    Ginxx009

    Joined:
    Sep 11, 2016
    Posts:
    89
    @Cherno sir im using your save/load system and in my project i have a Counter gameobject with a self script for counting everytime i click in the canvas and added your ObjectIdentifier script into the Counter gameobject my problem is the everytime i save my counter gameobject and load it it successfully load the last value of my counter but when i click again the canvas for adding it doesn't add anymore . Help me please
     
  29. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    @PaulKevin First of all, make sure that the Counter gameObject has a prefab in the Resources folder and that the prefab name has been set up correctly in the gameObject's (and prefab's) ObjectIdentifier script.

    I assume that your counter's reference to the canvas has been broken after loading, so make sure you re-establish this reference. For example, you could search for the canvas and assign it to the relevant variable in the counter script's OnLoad function.
     
  30. Cowboy433

    Cowboy433

    Joined:
    Jun 20, 2015
    Posts:
    1
    @Cherno You did a fantastic job with this, but I have one question. If I am saving one parent object with multiple child objects, would I have to add ObjectIdentifiers to each of the child objects, or just the parent object? Thanks!
    Edit: Also, how would I go about keeping all of my Drag and Drop GUI? Would I have to add PersistenceMarkers to all of the child objects for that as well?
     
    Last edited: Jan 30, 2017
  31. Ginxx009

    Ginxx009

    Joined:
    Sep 11, 2016
    Posts:
    89

    I already solved that problem sir . now my problem is whenever i add gameobjects like this
    see photo: http://imgur.com/a/14fKG

    and save it and then load it the gameobject i added on net count disappear. how can i solve this sir @Cherno
     
  32. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    @Cowboy433
    If the parent/child relationships change during runtime, then each gameobject, no matter if child or parent, needs an OI, and their prefabs can't have any parents/children which would be affected by the relationship changes.
    If no runtime changes take place, it's sufficient if the parent gameObject has an OI, and the prefab's child/parent relationship is the same as the one during saving/loading.

    For a drag & drop GUI the same rules apply. PersistenceMarkers only prevent a gameObject from being destroyed when loading a game.

    @PaulKevin GameObject references are reconnected only if the gameObject has an OI (The script's gameObject needs an OI as well of course).
     
  33. Ginxx009

    Ginxx009

    Joined:
    Sep 11, 2016
    Posts:
    89
    Thank you very much sir .
     
  34. Evasion4D

    Evasion4D

    Joined:
    Aug 8, 2013
    Posts:
    16
    @Cherno,

    I'm back...
    I try this new version but I still can not save the changes of materials
    I have selected "All" in Component Save Mode.

    If I change the color of the cube or sphere in runtime, it does not save them.
    In the cube, in TestScript, I change some values, but nothing is saved ...

    But positions, rotations, scale, all this is saved well

    How to do ?

    Regards,
    Jean Michel
     
  35. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    Make sure the Cube with the TestScript on it has a prefab in the Resources folder.

    For non-Mono components other than Transform, you need to read up on using the PropertySelector system. However, Materials are not serializable and I can't think of an easy way to write an ISerializationSurrogate for it so it'd probably be easier to create a custom solution for it via code. For example, having a script on the same gamebject that holds the name of the material, and a reference to the renderer, and then in OnSave assign the current material's name to the material name variable, and use it in OnLoad to pull the correct material from a global collection and assign it to the renderer.
     
  36. Evasion4D

    Evasion4D

    Joined:
    Aug 8, 2013
    Posts:
    16
    I use your demo scene "Save Load Test" and cube is well in Resources / Prefabs
    I do not know if this has an influence but I'm on MAC

    It's too bad that your system does not handle materials, it is the only thing I need ;)

    Good work anyway and thanks for your support :)
     
    Last edited: Feb 3, 2017
  37. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    Well, like I said, adding a workaround for Material support is trivial thanks to the OnSave and OnLoad functions.

    I haven't tested the system on Mac so it's possible that the problem is related to that.
     
  38. renesas

    renesas

    Joined:
    Feb 8, 2017
    Posts:
    1
    Hi, I am pretty new to unity and just stumbled over your plugin.
    I made a simple character creator using the free morph3D assets from the unity store and I can use sliders to manipulate certain aspects of the prefab (height, weight etc). Not sure if your system is even made for this, but it seemed to have saved something once and now I get an error everytime I press load or save

    EndOfStreamException: Failed to read past end of stream.
    System.IO.BinaryReader.ReadByte () (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/BinaryReader.cs:293)
    System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadNextObject (System.IO.BinaryReader reader) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs:142)
    System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectGraph (BinaryElement elem, System.IO.BinaryReader reader, Boolean readHeaders, System.Object& result, System.Runtime.Remoting.Messaging.Header[]& headers) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs:110)
    System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.NoCheckDeserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/BinaryFormatter.cs:179)
    System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/BinaryFormatter.cs:136)
    SaveLoad.GetSaveGames (System.String path, Boolean usePersistentDataPath) (at Assets/Unity Save Load Utility/SaveLoad.cs:229)
    SaveLoadMenu.OnGUI () (at Assets/Unity Save Load Utility/SaveLoadMenu.cs:105)

    No clue what I did wrong :D
     
  39. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    Sorry, I have no experience with that asset. If you want to save the prefab clone's settings, it's probably best if you prevent all fields and properties from being saved by using the USLU Attributes, and then add the fields one by one so you can see what causes the errors.
     
  40. Nisssha

    Nisssha

    Joined:
    Feb 20, 2017
    Posts:
    2
    I have a question. I tried everything to understand where the problem is and solve it myself, but I keep going back to point zero, so maybe you can help me.
    During runtime I instantiate a gameObject in script from prefab. It is childed to a gameObject in the scene and gets its transform.position from it. If I save and load the scene, it gets saved but not childed at all, even to the canvas. What do I do to make it save as a child?

    Update:
    I got a little further and object is now childed where it should be, but I keep getting this error:
    KeyNotFoundException: The given key was not present in the dictionary.
    System.Collections.Generic.Dictionary`2[System.String,ObjectIdentifier].get_Item (System.String key) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:150)
    SaveLoadUtility.LoadGame (System.String saveGameName) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:299)
    SaveLoadMenu.OnGUI () (at Assets/Unity Save Load Utility/SaveLoadMenu.cs:144)

    What can it be?
     
    Last edited: Feb 20, 2017
  41. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    Check if the GameObject has a script which holds a reference to another GameObject, Transform, or MonoBehaviour component.

    The line 299 in SaveLoadUtility is in the part that deals with reconnecting references to these Types. Make sure that both the parent object (canvas?) and the child object have OIs and that neither is marked as persistent.
     
  42. Nisssha

    Nisssha

    Joined:
    Feb 20, 2017
    Posts:
    2
    Hello, thank you for a fast reply:).

    Yes, my scripts are referencing another objects, and yes, it was an answer. Once I found how to instantiate prefabs without publicly exposing them it worked like a charm (even though all of the objects had OIs and no persistence markers;))! (In case anyone ever needs help with this, it's here: https://forum.unity3d.com/threads/how-to-get-prefabs-from-project-view-by-code.38274/ ).

    It's very plausible I will come back with more questions later (still not sure how to save sprites etc, but first I need to try myself). Thank you for this awesome asset and support with using it:).
     
  43. w34edrtfg

    w34edrtfg

    Joined:
    Nov 23, 2014
    Posts:
    72
    @Cherno this should be in the Asset Store or in GitHub so:
    - Gets more visibility (less time spend on deprecated packages)
    - People can collaborate (in github i mean)
    - Helps you have a rep in the store if you wanna ever upload any paid asset ;)
     
  44. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    Thanks, I already looked at moving it to the Asset Store but it requires, among other things, at least a semi-professional website for the developer, which I have yet to provide :)
     
  45. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    Double-clicking on the message in the console will bring you to the line of code that caused it.

    Make sure that you type in a name for the savegame when you save. If this information doesn't help, please describe the circumstances in greater detail.
     
  46. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    I can't say why it crashes. I suggest removing objects until it works again and go from there. It could be the number of objects you saved, or one specific type of component that causes problems, or something else.

    There are ways to speed up saving & loading, but this optimization needs to be done on your part and is project-specific. For example, instead of destroying and instantiating ALL objects in the scne/loaded file, you could check against some kind of map template if one object has been changed in any way, and only then decide to destroy or instantiate it. Especially terrain like buildings or trees will probably not change during gameplay so you could get by with leaving them the way they are as long as the maps are the same between the current running game and the saved game that is loaded.

    I'd like to stretch the fact that USLU is meant as a learning experience and a bare-bones base for your own saving/loading feature, not a complete all-around solution. It's designed to be understood by the user so he or she can adapt it the suit his or her needs :)
     
  47. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    No, the prefab specified by name in an object's ObjectIdentifier component has to be accessible somehow. However, this can eaily be circumverted by creating an empty gameobject upon loading, instead of instantiating a prefab clone, and adding the loaded component data.
     
  48. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    I can look into it this sunday.

    Be aware though that using seperate GameObjects for things loke blocks in a Minecraft-like world is generally a very bad idea for all bu the smallest of worlds. Unity can't handle the resulting huge numbers of GameObjects. Even a small world like 32x32x32 results in possibly 32768 GameObjects, far too many. Instead, use procedural mesh generation to create your blocks so that you only have a few chunks as individual GOs. It's how Minecraft does it too, after all. It has the added benefit that you only need to save and load the underlying data for each block position.
     
    Last edited: Feb 25, 2017
  49. a_user_that_codes

    a_user_that_codes

    Joined:
    Feb 23, 2017
    Posts:
    6
    Thank you! I might be able to do sunday but I just got in to a car crash so it depends. Thank you.
     
  50. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    I don't want any money. It's a free asset and if someone has a problem using it I try to help.