Search Unity

[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
    Take a look ath the SceneObject.cs class. It is basically a collection of data from one single gameObject in a form that lets it be serialized by the BinaryFormatter.
    The easiest way would be to have a generic prefab of the block objects, and set it's name as the ObjectIdentifier's prefab name. This will instantiate a clone of this prefab at the loaded block's position. The rest is just a matter of recreating data but how this is done depends on how your block system works. I think it would help if you would try to understand how the saving and loading of GameObjects / SceneObjects works in USLU. Also, be aware that saving and loading data is a very complex topic and not something I would recommend to a beginner. I only started dabbling in it after years of gaining experience in various other projects. So, if you still want to do it, be prepared to spend a lot of time reading and trial & error before anything works.
     
  2. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    Yes, the prefab has to have an OI component. I suggest reading the manual and quick start guide included with the USLU asset as it provides critical information.
     
  3. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    No, I can't come in to a call.
    There could be dozens if not hundreds of reasons behind the problem you are having. All I know is that in a clean new project that has the USLU imported, it will save and load GameObjects flawlessly (as long as the limitations detailed in the user manual are kept in mind).
     
  4. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    I just tested saving and loading in the test scene wupplied with the asset, in unity 5.5.0f3. I worked without any kind of problem. Please make sure that all prerequisites for saving and loading gameobjects in a scene have been met. Look at how the test scene is set up, make sure that the prefab your saved gameobject needs has been loaded into the prefab dictionary.

    Also, I'm not sure if I misunderstood you but it's completely normal that gameobjects get destroyed when loading. Of course, they should be instantiated again.
     
  5. pranavgadamsetty

    pranavgadamsetty

    Joined:
    Feb 16, 2017
    Posts:
    9
    Hi,

    I just tried out the demo in USLU. It saved the whole scene as an sav file. Is there a way save a Gameobject in the .obj format? I have used the objexport script found in Unity Community Wiki but, I'm looking for a way to do it during runtime say.... for example when i click a button.

    Regards,
    Pranav
     
  6. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    First of all: as far as using USLU (or any Binary Formatter) is concered, the file extension doesn't really matter; you can name it *.sav, *.dat, *.gam or whatever you like. However, the data that is written to that file doesn't change because the extension is changed. So, if you change it to *.obj, it won't magically create an object file for you to use in a 3d modeling application; it will remain a savegame file that can only be used by USLU.

    Now, as far as exporting models as *.obj during runtime goes; I believe at least one of the two available scripts from the wiki (one is two years old I believe, while the other one is newer) can already do this. Be aware that an *obj file contains only information related to the model, not Unity-specific things like components.
     
  7. pranavgadamsetty

    pranavgadamsetty

    Joined:
    Feb 16, 2017
    Posts:
    9
    Hi @Cherno,

    Thanks for the early reply. As you said, I used the "ObjExporter.cs" script file in Unity Community Wiki. I added the script to the gameobject's inspector and attached the gameobject to the Onclick() component of a button. But, neither the "MeshToString" function nor the "MeshToFile" function appear under the function options inside the OnClick() dialogue in the button's inspector menu. To test the script, I created another public void Test() function to see if my method is correct, and this function is apperaring under the functions menu. I dont know why the other functions are not available. Could you please help me with this? I have attached the images below for reference.

    Regards,
    Pranav
     

    Attached Files:

  8. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    I think you have to customize the function "DoExport(true)" of the ObjExporter.cs script to make it run outside of the Editor environment. As long as you just want to export, Editor or not, you can always select the Export menu option.
    However, this is not related to USLU so I think a new thread or Unity Answers might be a better place for this.
     
  9. pranavgadamsetty

    pranavgadamsetty

    Joined:
    Feb 16, 2017
    Posts:
    9
    Hi,

    Thanks for your help. Turns out, I just had to write another script to call the functions in "ObjExporter.cs" and add that custom script to the gameobject I wish to export. I know this isn't the right thread to discuss this question. I appreciate your prompt help.

    Regards,
    Pranav
     
  10. Kalita2127

    Kalita2127

    Joined:
    Dec 6, 2014
    Posts:
    279
    I've been looking for on how to save or loading a whole scene. And ended up found this great thread.
    I want to ask, can I save a whole scene with your plugin ? @Cherno I'm clueless about your script :/
     
  11. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    You can save a whole scene, yes. The manual and quickstart guide tell you all you need to know. However, without any modification, only gameobjects will be saved, on not things like the ambient light or skybox which are not stored on any GO. these things have to be saved by writing code for it manually.
     
  12. rodrigo1406

    rodrigo1406

    Joined:
    Apr 18, 2017
    Posts:
    1
    I'm using USLU in one of my projects and I'm having a trouble. I use the FirstPersonCharacter asset from Unity standard assets. I can't save the character position in my scene. How it works the USLU with that standard asset?
    Thanks in advice! And great job developing that
     
  13. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    It doesn't matter if the gameobject has a FPS Controller or not since USLU by default recognizes the Transform component every gameobject has and saves the position, rotation and scale values.
    Make sure that the gameobject you are trying to save has a corresponding prefab in your project's Resources folder.
     
  14. fanhieu8x

    fanhieu8x

    Joined:
    Dec 19, 2016
    Posts:
    4
    Hi Cherno

    I'm using USLU (downloaded from 05-May-2017) in my project, it is occurred error "StackOverflowException" when save game by using LoadSaveUtility.SaveGame(string)

    Error message detail as bellow:
    StackOverflowException
    UnityEngine.GameObject.GetComponent[ObjectIdentifier] () (at /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/GameObjectBindings.gen.cs:35)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:798)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict, Boolean checkForPropertySelector) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:677)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:571)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:967)
    SaveLoadUtility.GetCollectionElement (System.Type fieldType, Int32 index, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:747)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:895)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict, Boolean checkForPropertySelector) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:677)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:571)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:967)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict, Boolean checkForPropertySelector) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:677)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:571)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:967)
    SaveLoadUtility.GetCollectionElement (System.Type fieldType, Int32 index, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:747)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:895)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict, Boolean checkForPropertySelector) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:677)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:571)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:967)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict, Boolean checkForPropertySelector) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:677)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:571)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:967)
    SaveLoadUtility.GetCollectionElement (System.Type fieldType, Int32 index, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:747)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:895)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict, Boolean checkForPropertySelector) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:677)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:571)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:967)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict, Boolean checkForPropertySelector) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:677)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:571)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:967)
    SaveLoadUtility.GetCollectionElement (System.Type fieldType, Int32 index, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:747)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:895)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict, Boolean checkForPropertySelector) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:677)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:571)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:967)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict, Boolean checkForPropertySelector) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:677)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:571)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:967)
    SaveLoadUtility.GetCollectionElement (System.Type fieldType, Int32 index, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:747)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:895)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict, Boolean checkForPropertySelector) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:677)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:571)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:967)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict, Boolean checkForPropertySelector) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:677)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:571)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:967)
    SaveLoadUtility.GetCollectionElement (System.Type fieldType, Int32 index, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:747)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:895)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict, Boolean checkForPropertySelector) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:677)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:571)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:967)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict, Boolean checkForPropertySelector) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:677)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:571)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:967)
    SaveLoadUtility.GetCollectionElement (System.Type fieldType, Int32 index, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:747)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:895)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict, Boolean checkForPropertySelector) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:677)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:571)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:967)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict, Boolean checkForPropertySelector) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:677)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:571)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:967)
    SaveLoadUtility.GetCollectionElement (System.Type fieldType, Int32 index, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:747)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:895)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict, Boolean checkForPropertySelector) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:677)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:571)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:967)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict, Boolean checkForPropertySelector) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:677)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:571)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:967)
    SaveLoadUtility.GetCollectionElement (System.Type fieldType, Int32 index, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:747)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:895)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict, Boolean checkForPropertySelector) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:677)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:571)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:967)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict, Boolean checkForPropertySelector) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:677)
    SaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:571)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:967)
    SaveLoadUtility.GetCollectionElement (System.Type fieldType, Int32 index, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:747)
    SaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName<message truncated>


    Please help and tell me why?
    Thanks.
     

    Attached Files:

  15. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    Does the error occur when trying to save the provided sample scene? If not, then it's hard to find the exact reason for the error. Some field in one of the components you are trying to save doesn't play nice, so you will have to remove them from the saving (or loading) queue by using the DontSaveMember attribute one by one until you hit the right one.
     
  16. orioldarmengol

    orioldarmengol

    Joined:
    Apr 14, 2017
    Posts:
    1
    hello,
    i have this error to start game
    ArgumentException: An element with the same key already exists in the dictionary.
    System.Collections.Generic.Dictionary`2[System.String,UnityEngine.GameObject].Add (System.String key, UnityEngine.GameObject value) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:404)
    SaveLoadUtility.Start () (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:130)

    and this in some objects to save and load:

    [UnpackGameObject] Can't find key obj_flower_daisy in SaveLoadUtility.prefabDictionary!
    UnityEngine.Debug:Log(Object)
    SaveLoadUtility:UnpackGameObject(SceneObject, GameObject) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:981)
    SaveLoadUtility:LoadGame(String) (at Assets/Unity Save Load Utility/SaveLoadUtility.cs:258)
    scriptMenu:pulsarLoad() (at Assets/Scripts/scriptMenu.cs:161)
    UnityEngine.EventSystems.EventSystem:Update()

    all error come after change multiple objects in scene and change all gameobject names.
    the problem maybe its provocate because the dictionary have the old name?
    if its that, how i can reset dictionary?

    thanks, and sorry for my english
     
  17. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    1. I assume that you have two gameobjects with the same name or objectidentifier prefabname inside your project folder.
    2. You can reset the dictionary to reload all prefabs. Check the SaveLoadUtility script, in the start or awake function there should be a piece of code that does just that. I'm not at home atm so I can't check.
     
  18. elvismart

    elvismart

    Joined:
    Mar 9, 2013
    Posts:
    2
    Hey there I'm experimenting with unity and i am stuck with save and load, your solution seems the best for beginners, i played with the testcube and script and they work fine, but when i try to implement them into my game it doesn't work, i have created just a map and i have a canvas with buttons on it that have a spawnprefab onclick function to instantiate the object, whenever i run the project the test cube that came from your package is saved and loaded normally but the objects that i spawn and im trying to save dissapear on load and only the last one spawned is saved. Any idea how to solve this?
     
    Last edited: Jun 2, 2017
  19. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    Make sure that you followed all the steps in the Quick Start Guide. A common problem is that an object to be loaded has no prefab, or that the prefab name in it's ObjectIdentifier component is wrong.
     
  20. KKS21199

    KKS21199

    Joined:
    Nov 22, 2012
    Posts:
    139
    Thanks for the asset. Saved me loads of time writing my own serialization for gameobjects. I have added a few functions to support my needs (eg instantiate gameobjects by searching a .asset file list if a certain component is present in the gameobject).

    There is one bug that I found, the ObjectIdentifier.dontSave doesn't work. The fix was simple,

    Code (CSharp):
    1.     //Go through the OIsToSerialize array again to pack the GameObjects into serializable form, and add the packed data to the sceneObjects list of the new SaveGame instance.
    2.         if(true) {
    3.             foreach (ObjectIdentifier oi in OIsToSerialize) {
    4.                 //Convert the GameObject's data into a form that can be serialized (an instance of SceneObject),
    5.                 //and add it to the SaveGame instance's list of SceneObjects.
    6.                                 newSaveGame.sceneObjects.Add(PackGameObject(oi.gameObject, oi));
    7.             }
    8.         }
    to

    Code (CSharp):
    1.     //Go through the OIsToSerialize array again to pack the GameObjects into serializable form, and add the packed data to the sceneObjects list of the new SaveGame instance.
    2.         if(true) {
    3.             foreach (ObjectIdentifier oi in OIsToSerialize) {
    4.                 //Convert the GameObject's data into a form that can be serialized (an instance of SceneObject),
    5.                 //and add it to the SaveGame instance's list of SceneObjects.
    6.                 if (oi.dontSave == false)
    7.                     newSaveGame.sceneObjects.Add(PackGameObject(oi.gameObject, oi));
    8.             }
    9.         }
    in SaveGame() SaveLoadUtility.cs

    I am not sure about the line as I have already modified the scripts to support my game.

    As others suggested it would be great if you can start the project in github repository.

    Also, the current script does not support different scene data's (especially when persistent data path is used). I will add a fix when I do work around it later.
     
    Cherno likes this.
  21. elvismart

    elvismart

    Joined:
    Mar 9, 2013
    Posts:
    2
    Code (CSharp):
    1. using System.Collections; using System.Collections.Generic; using UnityEngine;
    2. public class ChangeColor : MonoBehaviour {
    3.  
    4. public Material[] materials;
    5. public Renderer rend;
    6.  
    7. private int index = 1;
    8.  
    9. // Use this for initialization
    10. void Start () {
    11. rend = GetComponent<Renderer>();
    12. rend.enabled = true;
    13. }
    14.  
    15. // Update is called once per frame
    16. void OnMouseUp () {
    17.  
    18. if(materials.Length == 0)
    19. {
    20. return;
    21. }
    22.  
    23. if(Input.GetMouseButtonUp(0) && Input.GetKey("e"))
    24. {
    25. index += 1;
    26. if(index == materials.Length + 1)
    27. {
    28. index = 1;
    29. }
    30. rend.sharedMaterial = materials[index - 1];
    31. }
    32.  
    33. if (Input.GetMouseButtonUp(0) && Input.GetKey("q"))
    34. {
    35. Destroy(gameObject);
    36. }
    37. } }
    I found the problem it is this script that I'm using, all the objects except the last one get destroyed with that, without it things save and load fine, is there anyway to make it work with it?
    I copy pasted the code on my smartphone so it might look bad.
     
  22. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    I don't know why this particular script causes problems.
     
  23. jo82

    jo82

    Joined:
    Dec 3, 2015
    Posts:
    47
    Hi

    I cannot save/load the color even if the cube's in Resources folder, has TestScript.cs on and is marked "all" in component save mode.
     
  24. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    If you change the renderer's material's color at runtime, then you will have to redo that again after loading, for example by using the OnLoad function.
     
  25. TunacornStudios

    TunacornStudios

    Joined:
    Jun 14, 2017
    Posts:
    4
    Hi Cherno,
    I am wondering if this asset is free to use in a commercial game. I am willing to completely credit you and make no changes to the package.
    Cheers,
    Tunacorn Studios (username change pending)
     
  26. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    You may use the package in any way you like. A credit is appreciated but not neccessary. If someone uses this asset as a base to modify and build their own save game system on, then that's exactly what this was meant for :)
     
  27. ColtonKadlecik_VitruviusVR

    ColtonKadlecik_VitruviusVR

    Joined:
    Nov 27, 2015
    Posts:
    197
    Hey @Cherno ,
    Thanks for posting this it looks great! Quick question I have before implementing it, has it been tested on PS4? Does it work? Should there be any reason why it does not work?
    Cheers,
    Colton
     
  28. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
  29. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    Hi,

    A really good stuff.

    I have a lot of objects that I don't want to be destroyed during loading a saved scene. They all must have the PersistenceMarker script attached? Is there other way to prevent them from destroying?
     
  30. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    Yes, but you could easily change this functionality since. For example, you could give them a tag or even layer and then in the ClearScene function (I can't remember the exact name of the function atm) when all Objects are collected and iterated over, don't just check for the persistence marker but also if they have the tag, are in a certain layer, have some Mono script, or whatever. Don't be afraid to dive into the provided scripts, they have lots of comments that will help you understand how it all works.
     
  31. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    I did something like that:
    Code (csharp):
    1.  
    2. //Clear the scene of all non-persistent GameObjects so we have a clean slate
    3.    public void ClearScene() {
    4.        object[] obj = GameObject.FindObjectsOfType(typeof (GameObject));
    5.        foreach (object o in obj) {
    6.            GameObject go = (GameObject) o;
    7.  
    8.            //if the GameObject has a PersistentGameObject component, ignore it. (Cameras, Managers, etc. which should survive loading)
    9.            //these kind of GO's shouldn't have an ObjectIdentifier component! You can save and load single components with the PackComponent and UnpackComponent methods.
    10.            //An empty component is used to mark a GameObject as persistent so the tag is still available for other uses
    11.            if(go.GetComponent<SLNonPersistenceMarker>() || go.GetComponent<SLObjectIdentifier>()) {
    12.                Destroy(go);
    13.                if(debugController.destroyingGameObject) {
    14.                    Debug.Log("[ClearScene] " + "Destroying GameObject: " + go.name);
    15.                }
    16.                continue;
    17.            }
    18.            if(debugController.isPersistent) {
    19.                Debug.Log("[ClearScene] " + "Keeping peristent GameObject: " + go.name);
    20.            }
    21.            
    22.        }
    23.    }
    24.  
     
    Cherno likes this.
  32. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    I save with the function (a button click):
    Code (csharp):
    1.  
    2. public void OnSaveScene(){
    3.        string saveGameName = inputFieldGameName.text;
    4.        
    5.        if(saveGameName != ""){
    6.            slu.SaveGame(saveGameName);
    7.        }else{
    8.            Debug.Log("Enter a save game name");
    9.        }
    10.    }
    11.  
    12.  
    I get the error during saving:
    Code (csharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3. SLSaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SLSaveLoadUtility.cs:881)
    4. SLSaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict, Boolean checkForPropertySelector) (at Assets/Unity Save Load Utility/SLSaveLoadUtility.cs:688)
    5. SLSaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict) (at Assets/Unity Save Load Utility/SLSaveLoadUtility.cs:582)
    6. SLSaveLoadUtility.WriteToDictionary (System.Type fieldType, System.String fieldName, System.Object fieldValue, System.Collections.Generic.Dictionary`2& baseDict, Boolean isField) (at Assets/Unity Save Load Utility/SLSaveLoadUtility.cs:978)
    7. SLSaveLoadUtility.GetValues (System.Object baseInstance, System.Collections.Generic.Dictionary`2& baseDict, Boolean checkForPropertySelector) (at Assets/Unity Save Load Utility/SLSaveLoadUtility.cs:688)
    8. SLSaveLoadUtility.PackComponent (System.Object component) (at Assets/Unity Save Load Utility/SLSaveLoadUtility.cs:576)
    9. SLSaveLoadUtility.PackGameObject (UnityEngine.GameObject go, .SLObjectIdentifier oi) (at Assets/Unity Save Load Utility/SLSaveLoadUtility.cs:534)
    10. SLSaveLoadUtility.SaveGame (System.String saveGameName) (at Assets/Unity Save Load Utility/SLSaveLoadUtility.cs:210)
    11. SLSaveLoadMenu.OnSaveScene () (at Assets/Unity Save Load Utility/SLSaveLoadMenu.cs:112)
    12. UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:154)
    13. UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:637)
    14. UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:773)
    15. UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:52)
    16. UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35)
    17. UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44)
    18. UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:50)
    19. UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:261)
    20. UnityEngine.EventSystems.EventSystem:Update()
    21.  
     
  33. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    Try to find out which field or property is causing the error.
     
  34. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    Your default objects (the cube and the sphere) work great. I have my own prefabs in Resource folders. In this code (SaveLoadUtility) the prefabs are loaded in the Start function, and at runtime I change the name of instances of prefabs that should be saved. So different names in the collection and in the scene can be a problem. I need to refresh the collection of prefabs, not only load in the Start(). What do you think?

    Code (csharp):
    1.  
    2. prefabDictionary = new Dictionary<string, GameObject>();
    3.            prefabs_oi = Resources.LoadAll<SLObjectIdentifier>("Items");
    4.            foreach(SLObjectIdentifier oi in prefabs_oi) {
    5.                prefabDictionary.Add (oi.gameObject.name,oi.gameObject);
    6.                if(debugController.loadPrefab) {
    7.                    Debug.Log("Added GameObject to prefabDictionary: " + oi.gameObject.name);
    8.                }
    9.            }
    10.  
    11.  
    What to do with objects that must be saved and loaded and they aren't in Resource folder? They exist in the scene only.
     
    Last edited: Jun 24, 2017
  35. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    For these cases, you have to completely recreate the gameobject from scratch, meaning: Collecting their data (position etc as well as components and values stored therein) and when loading, adding and applying this data to an empty gameobject. It's basically not that different from doing it the prefab way except that you take care of ALL components yourself.
     
  36. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    I understand that your tool won't do that. I must use my solution. OK.

    //Load all ObjectIdentifier components in the Resources folder hierarchy and fill the prefabDictionary with their GameObjects.
    //This allows the utility to instantiate GameObjects that were saved after loading.
    //Note that all prefabs that should be affected by saving and loading must have an ObjectIdentifier component attached.

    So what happen if I change the name of any instance of prefabs that should be saved and loaded at runtime? The names are different than those in the public SLObjectIdentifier[] prefabs_oi; (all prefabs loaded from the resources folder).
     
  37. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    What's important is the prefabName of the OI when it's packed into a SceneObject instance while saving, and the string key value of the prefab dictionary that leads to the right prefab gameobject when loading.
     
  38. Tomza

    Tomza

    Joined:
    Aug 27, 2013
    Posts:
    596
    So if i spawn a prefab and at runtime I change its name, your tool should work?
     
  39. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    Since you don't actually spawn a prefab but rather instantiate a copy of a prefab which is in any way a regular gameobject in the scene (save for a possible prefab connection) it doesn't matter what name this gameobject has as far as USLU is concerned. That being said, I am not 100% sure about if, when and how chaning any value of the instantiated gameobject (including it's name) might affect the prefab through an existing conection so you might want to do some simple testing to see if that could cause for an error.
     
  40. shubham5577

    shubham5577

    Joined:
    Jan 2, 2017
    Posts:
    3
    Hii Cherno,
    You rocks you are really awesome man Hats off to you man. I have tried your asset it was really great.But bro I want also to save activation and deactivation of my gameobject.so bro please tell me.What i need to do.
    thanks once again.:))
     
  41. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    This is a little complicated because Unity can't find inactive GameObjects, so they can beither be saved nor destroyed when saving and loading. Two workarounds come to my mind:

    1. Disable all components which are affects how the gameobject functions in any way. For example, you can set a RigidBody to kinematic, disable colliders, and also disable scripts which make an object move etc. This would still leave the GameObject itself active and thus Unity can find it any time while still being effectively "not there" in the scene since it won't affect itself or be affected by anything else.

    2. Keep track of all GameObjects in some kind of collection or system consisting of multiple collections, for example something like an Object Pooling system. You would need to create a reference to every GameObject once it is created and ideally also delete the references once it is destroyed. This potentially requires a lot of work to get it to function reliably. You can then make USLU access even Inactive GameObjects by using the references.
     
  42. shubham5577

    shubham5577

    Joined:
    Jan 2, 2017
    Posts:
    3
  43. shubham5577

    shubham5577

    Joined:
    Jan 2, 2017
    Posts:
    3
    Hii cherno,
    I want to save the data automatically. i dont want to click on save/load button to saving the data.I tried to do this myself by moving the Save and load pograms to Start and Update function.I moved the load function to Start and save function to Update.But Bro i didnt work so what i need to do please help me out.
    Thanks in advance.
     
  44. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    I don't know what you mean by "moving the Save and load pograms to Start and Update function". All you should need to do is take the code that gets called when clicking the button and put it somewhere else, like in the Start function of any script. It would help if you could explain when the data is supposed to be saved.
     
  45. Narendraom

    Narendraom

    Joined:
    Jul 8, 2015
    Posts:
    35
    Hello Cherno,

    Great work and thanks for providing us such type of package it helps me a lot. I had made some changes in SLU script and SaveLoad so that I can save so many scenes in our directory and can load any scene I want. Everything working like charm on Windows PC, Android and even on MAC. But for iPhone it gives error. If I save same scene working on iPhone it will work but when I create a scene from Mac and load that in iPhone it gives exception. I am stuck here please help me. Thanks in advance

    System.TypeLoadException: A type load exception has occurred.

    at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetDeserializationType (Int64 assemblyId, System.String className) [0x00000] in <filename unknown>:0

    at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadTypeMetadata (System.IO.BinaryReader reader, Boolean isRuntimeObject, Boolean hasTypeInfo) [0x00000] in <filename unknown>:0

    at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectInstance (System.IO.BinaryReader reader, Boolean isRuntimeObject, Boolean hasTypeInfo, Int64& objectId, System.Object& value, System.Runtime.Serialization.SerializationInfo& info) [0x00000] in <filename unknown>:0

    at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObject (BinaryElement element, System.IO.BinaryReader reader, Int64& objectId, System.Object& value, System.Runtime.Serialization.SerializationInfo& info) [0x00000] in <filename unknown>:0

    at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadNextObject (System.IO.BinaryReader reader) [0x00000] in <filename unknown>:0

    at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectGraph (BinaryElement elem, System.IO.BinaryReader reader, Boolean readHeaders, System.Object& result, System.Runtime.Remoting.Messaging.Header[]& headers) [0x00000] in <filename unknown>:0

    at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.NoCheckDeserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler) [0x00000] in <filename unknown>:0
     
  46. MCrafterzz

    MCrafterzz

    Joined:
    Jun 3, 2017
    Posts:
    354
    Hello, I'm reading thought the code to try and understand how it works. I thing that I don't understand is what the prefabs are for. You are saving the component data ect into a file and then recreating a gameobject with that data, so why are the prefabs needed?. Or am I totally wring? Also thanks for creating such a awsome tool!
     
  47. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
    Having prefabs makes it easier to reconstruct gameobjects as most if not all components are already on them so only very little has to be added or removed in that regard. One could theoretically just create an empty gameobject from scratch and fill it with the data from the save file but it would increase the volume of the data tremendously since literally everything has to be saved, especially when it comes to children.
     
  48. MCrafterzz

    MCrafterzz

    Joined:
    Jun 3, 2017
    Posts:
    354
    Ok thanks for your reply!
     
  49. TunacornStudios

    TunacornStudios

    Joined:
    Jun 14, 2017
    Posts:
    4
    Hey Cherno, is it possible to add a way to make it so an entire script won't get serialised? and possible way to call an event on serialization and un serialization?
     
  50. TunacornStudios

    TunacornStudios

    Joined:
    Jun 14, 2017
    Posts:
    4
    Nevermind, I worked it out :)