Just Want to Save and Load the Game?

Discussion and help for Easy Save 3
Post Reply
westingtyler
Posts: 28
Joined: Tue May 10, 2016 4:00 pm

Just Want to Save and Load the Game?

Post by westingtyler »

I just want players to press the S key to save their game, then press the L key to load their game. I'm using Playmaker and can't find actions to do this.

There are actions to save and load various types of information, but i can't find a "Save game state" or "load game state" action anywhere. Am I just missing something?

There's only one level, where you can use various pieces to create a map. The pieces already exist in the scene, and you just move and place them, and you can create prefab lines and lock images and connect doors that way.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Just Want to Save and Load the Game?

Post by Joel »

Hi there,

It's not possible to save the entire game state automatically, because much of a scene is not serialisable at runtime, or does not require serialising.

You should use the Save and Load actions to save and load the Fsm variables which need persisting, and use these to restore your scene.

With regards to saving on a button press, your best bet is to ask on the Playmaker forums regarding how to trigger an event using a button press. However, looking at their documentation it looks like the UI CLICKS event is what you require: https://hutonggames.fogbugz.com/default.asp?W128

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
westingtyler
Posts: 28
Joined: Tue May 10, 2016 4:00 pm

Re: Just Want to Save and Load the Game?

Post by westingtyler »

Hey, thanks for the info.

I really just need to save the vector 3 locations of a series of game objects (the map pieces)

and the fact that a series of prefab "lines" have been created, oriented, and placed. Currently none of this is being saved in the scene as fsm variables. what is the simplest way to go about getting all this info when i need to save it? something like, find all objects with tag 'map pieces', add them to an array. make a second array of their names, make a third array of their v3's. save each array to a file somehow? then after starting the game again, load those files into their arrays, finding the game objects again, comparing the names to determine where to place which one?
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Just Want to Save and Load the Game?

Post by Joel »

Hi there,

How you've described it is indeed how I would do it in PlayMaker.

Once you've got your names and positions into arrays, you can then save them using the Save action, with the Type set to Array, and the value set to your array variable.

You can then use the Load action to load those arrays. You would then use the name to identify which prefab to instantiate, and then assign the corresponding position from the positions array to that instantiated prefab.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
westingtyler
Posts: 28
Joined: Tue May 10, 2016 4:00 pm

Re: Just Want to Save and Load the Game?

Post by westingtyler »

This is exciting. I need to save 9 total arrays; for map pieces, lines, and stamps, I need to save a name, a position v3, and a rotation v3.

is it safe to save ALL of these 9 arrays into a single file? would it be reasonable to create a file with a name the user specifies and save these things to it? could users then trade these files to see each other's custom maps? what if players dumped a bunch of these saves into a folder; can I use a "make an array of names of files in this folder" action to populate a list of "load file X..." buttons that can be clicked on to load different savefiles?
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Just Want to Save and Load the Game?

Post by Joel »

Hi there,

It is indeed safe to save these all into the same file. You can then use the Get Files action to get all of the files in a directory, which you can iterate over and display in the GUI.

When the user selects a filename, you could put this into a variable, and then set the Path of the Load action to this filename. Note that you need to check the "Override Default Settings" checkbox for the Path variable to be visible in the Load action.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
westingtyler
Posts: 28
Joined: Tue May 10, 2016 4:00 pm

Re: Just Want to Save and Load the Game?

Post by westingtyler »

hello. when loading an array of game objects or strings, should I use Load or Load Into? What is the functional difference?

I'm using Save and Load actions so far. If I place some lines in the game (saving each go to a Line go array) then i hit Save, it seems to work. If I then delete one of the game objects then hit Save again, i get this error:

saveable arrays : saveable arrays : save line go's : Save : UnityEngine.MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
at (wrapper managed-to-native) UnityEngine.GameObject:GetComponentFastPath (System.Type,intptr)
at UnityEngine.GameObject.GetComponent[ES3Prefab] () [0x00020] in C:\buildslave\unity\build\Runtime\Export\GameObject.bindings.cs:28
at ES3Types.ES3Type_GameObject.Write (System.Object obj, .ES3Writer writer) [0x0002c] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Types\Unity Types\ES3Type_GameObject.cs:26
at ES3Types.ES3Type.WriteUsingDerivedType (System.Object obj, .ES3Writer writer) [0x00025] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Types\ES3Type.cs:45
at ES3Types.ES3ObjectType.Write (System.Object obj, .ES3Writer writer) [0x00004] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Types\ES3ObjectType.cs:22
at ES3Writer.Write (System.Object value, ES3Types.ES3Type type, ReferenceMode memberReferenceMode) [0x000a1] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Writers\ES3Writer.cs:153
at ES3Types.ES3ArrayType.Write (System.Object obj, .ES3Writer writer, ReferenceMode memberReferenceMode) [0x00048] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Types\Collection Types\ES3ArrayType.cs:25
at ES3Types.ES3CollectionType.Write (System.Object obj, .ES3Writer writer) [0x00005] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Types\Collection Types\ES3CollectionType.cs:35
at ES3Types.ES3Type.WriteUsingDerivedType (System.Object obj, .ES3Writer writer) [0x00025] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Types\ES3Type.cs:45
at ES3Types.ES3ObjectType.Write (System.Object obj, .ES3Writer writer) [0x00004] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Types\ES3ObjectType.cs:22
at ES3Writer.Write (System.Object value, ES3Types.ES3Type type, ReferenceMode memberReferenceMode) [0x000a1] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Writers\ES3Writer.cs:153
at ES3Writer.WriteProperty (System.String name, System.Object value, ES3Types.ES3Type type, ReferenceMode memberReferenceMode) [0x0000d] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Writers\ES3Writer.cs:204
at ES3Writer.Write[Object] (System.String key, System.Object value) [0x00041] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Writers\ES3Writer.cs:87
at ES3.Save[Object] (System.String key, System.Object value, .ES3Settings settings) [0x0000c] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\ES3.cs:40
at ES3PlayMaker.Save.Enter () [0x00028] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\PlayMaker\ES3PlayMaker.cs:171
at ES3PlayMaker.ActionBase.OnEnter () [0x00003] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\PlayMaker\ES3PlayMaker.cs:34
UnityEngine.Debug:LogError(Object, Object)
HutongGames.PlayMaker.FsmLog:AddEntry(FsmLogEntry, Boolean) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmLog.cs:172)
HutongGames.PlayMaker.FsmLog:LogAction(FsmLogType, String, Boolean) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmLog.cs:361)
HutongGames.PlayMaker.FsmStateAction:LogError(String) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmStateAction.cs:280)
ES3PlayMaker.ActionBase:HandleError(String) (at Assets/Plugins/Easy Save 3/PlayMaker/ES3PlayMaker.cs:56)
ES3PlayMaker.ActionBase:OnEnter() (at Assets/Plugins/Easy Save 3/PlayMaker/ES3PlayMaker.cs:38)
HutongGames.PlayMaker.FsmState:ActivateActions(Int32) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:205)
HutongGames.PlayMaker.FsmState:OnEnter() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:175)
HutongGames.PlayMaker.Fsm:EnterState(FsmState) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2767)
HutongGames.PlayMaker.Fsm:SwitchState(FsmState) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2714)
HutongGames.PlayMaker.Fsm:UpdateStateChanges() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2642)
HutongGames.PlayMaker.Fsm:DoTransition(FsmTransition, Boolean) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2681)
HutongGames.PlayMaker.Fsm:ProcessEvent(FsmEvent, FsmEventData) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2252)
HutongGames.PlayMaker.Fsm:SendEventToFsmOnGameObject(GameObject, String, FsmEvent) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2621)
HutongGames.PlayMaker.Fsm:Event(FsmEventTarget, FsmEvent) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2388)
HutongGames.PlayMaker.Actions.SendEvent:OnEnter() (at Assets/PlayMaker/Actions/StateMachine/SendEvent.cs:42)
HutongGames.PlayMaker.FsmState:ActivateActions(Int32) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:205)
HutongGames.PlayMaker.FsmState:OnEnter() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:175)
HutongGames.PlayMaker.Fsm:EnterState(FsmState) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2767)
HutongGames.PlayMaker.Fsm:SwitchState(FsmState) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2714)
HutongGames.PlayMaker.Fsm:UpdateStateChanges() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2642)
HutongGames.PlayMaker.Fsm:UpdateState(FsmState) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2783)
HutongGames.PlayMaker.Fsm:Update() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:1994)
PlayMakerFSM:Update() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/PlayMakerFSM.cs:579)

=

how do I check if it's null as it says? I just want to save the contents of the array and load onto that array, regardless of which indexes have been cleared?

when i load, the game objects don't have a material. It seems to save the game object and its children, and all its properties and mesh, but not its material? is that right that it saves everything about the game object except its material?
error save lines.PNG
error save lines.PNG (152.48 KiB) Viewed 9601 times
Last edited by westingtyler on Sun Sep 02, 2018 3:21 pm, edited 1 time in total.
westingtyler
Posts: 28
Joined: Tue May 10, 2016 4:00 pm

Re: Just Want to Save and Load the Game?

Post by westingtyler »

The problem I'm running into, is that I can save and load game objects into the scene from a file of saved arrays, but they have no material when loaded.

so I made an array to save their materials and load them as well, but when I try to save I get this error:
error instance playmaker.PNG
error instance playmaker.PNG (195.9 KiB) Viewed 9584 times




saveable arrays : saveable arrays : mat 2 : Save : System.NotSupportedException: Type of UnityEngine.Texture is not supported as it does not have a parameterless constructor. Only value types, Components or ScriptableObjects are supportable without a parameterless constructor. However, you may be able to create an ES3Type script to add support for it.
at ES3Internal.ES3TypeMgr.CreateES3Type (System.Type type, Boolean throwException) [0x00221] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Types\ES3TypeMgr.cs:101
at ES3Internal.ES3TypeMgr.GetOrCreateES3Type (System.Type type, Boolean throwException) [0x0002b] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Types\ES3TypeMgr.cs:23
at ES3Writer.WriteProperty[Texture] (System.String name, System.Object value) [0x00015] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Writers\ES3Writer.cs:212
at ES3Types.ES3Type_Material.WriteUnityObject (System.Object obj, .ES3Writer writer) [0x000fd] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Types\Unity Types\ES3Type_Material.cs:28
at ES3Types.ES3UnityObjectType.WriteObject (System.Object obj, .ES3Writer writer, ReferenceMode mode) [0x0005a] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Types\ES3UnityObjectType.cs:40
at ES3Types.ES3UnityObjectType.WriteObject (System.Object obj, .ES3Writer writer) [0x00005] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Types\ES3UnityObjectType.cs:22
at ES3Types.ES3ObjectType.Write (System.Object obj, .ES3Writer writer) [0x00011] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Types\ES3ObjectType.cs:23
at ES3Types.ES3Type.WriteUsingDerivedType (System.Object obj, .ES3Writer writer) [0x00025] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Types\ES3Type.cs:45
at ES3Types.ES3ObjectType.Write (System.Object obj, .ES3Writer writer) [0x00004] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Types\ES3ObjectType.cs:22
at ES3Writer.Write (System.Object value, ES3Types.ES3Type type, ReferenceMode memberReferenceMode) [0x000a1] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Writers\ES3Writer.cs:153
at ES3Types.ES3ArrayType.Write (System.Object obj, .ES3Writer writer, ReferenceMode memberReferenceMode) [0x00048] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Types\Collection Types\ES3ArrayType.cs:25
at ES3Types.ES3CollectionType.Write (System.Object obj, .ES3Writer writer) [0x00005] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Types\Collection Types\ES3CollectionType.cs:35
at ES3Types.ES3Type.WriteUsingDerivedType (System.Object obj, .ES3Writer writer) [0x00025] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Types\ES3Type.cs:45
at ES3Types.ES3ObjectType.Write (System.Object obj, .ES3Writer writer) [0x00004] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Types\ES3ObjectType.cs:22
at ES3Writer.Write (System.Object value, ES3Types.ES3Type type, ReferenceMode memberReferenceMode) [0x000a1] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Writers\ES3Writer.cs:153
at ES3Writer.WriteProperty (System.String name, System.Object value, ES3Types.ES3Type type, ReferenceMode memberReferenceMode) [0x0000d] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Writers\ES3Writer.cs:204
at ES3Writer.Write[Object] (System.String key, System.Object value) [0x00041] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\Writers\ES3Writer.cs:87
at ES3.Save[Object] (System.String key, System.Object value, .ES3Settings settings) [0x0000c] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\Scripts\ES3.cs:40
at ES3PlayMaker.Save.Enter () [0x00028] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\PlayMaker\ES3PlayMaker.cs:171
at ES3PlayMaker.ActionBase.OnEnter () [0x00003] in C:\Spencer Mapper\Assets\Plugins\Easy Save 3\PlayMaker\ES3PlayMaker.cs:34
UnityEngine.Debug:LogError(Object, Object)
HutongGames.PlayMaker.FsmLog:AddEntry(FsmLogEntry, Boolean) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmLog.cs:172)
HutongGames.PlayMaker.FsmLog:LogAction(FsmLogType, String, Boolean) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmLog.cs:361)
HutongGames.PlayMaker.FsmStateAction:LogError(String) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmStateAction.cs:280)
ES3PlayMaker.ActionBase:HandleError(String) (at Assets/Plugins/Easy Save 3/PlayMaker/ES3PlayMaker.cs:56)
ES3PlayMaker.ActionBase:OnEnter() (at Assets/Plugins/Easy Save 3/PlayMaker/ES3PlayMaker.cs:38)
HutongGames.PlayMaker.FsmState:ActivateActions(Int32) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:205)
HutongGames.PlayMaker.FsmState:OnEnter() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:175)
HutongGames.PlayMaker.Fsm:EnterState(FsmState) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2767)
HutongGames.PlayMaker.Fsm:SwitchState(FsmState) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2714)
HutongGames.PlayMaker.Fsm:UpdateStateChanges() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2642)
HutongGames.PlayMaker.Fsm:DoTransition(FsmTransition, Boolean) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2681)
HutongGames.PlayMaker.Fsm:ProcessEvent(FsmEvent, FsmEventData) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2252)
HutongGames.PlayMaker.Fsm:SendEventToFsmOnGameObject(GameObject, String, FsmEvent) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2621)
HutongGames.PlayMaker.Fsm:Event(FsmEventTarget, FsmEvent) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2388)
HutongGames.PlayMaker.Actions.SendEvent:OnEnter() (at Assets/PlayMaker/Actions/StateMachine/SendEvent.cs:42)
HutongGames.PlayMaker.FsmState:ActivateActions(Int32) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:205)
HutongGames.PlayMaker.FsmState:OnEnter() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:175)
HutongGames.PlayMaker.Fsm:EnterState(FsmState) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2767)
HutongGames.PlayMaker.Fsm:SwitchState(FsmState) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2714)
HutongGames.PlayMaker.Fsm:UpdateStateChanges() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2642)
HutongGames.PlayMaker.Fsm:UpdateState(FsmState) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2783)
HutongGames.PlayMaker.Fsm:Update() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:1994)
PlayMakerFSM:Update() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/PlayMakerFSM.cs:579)
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Just Want to Save and Load the Game?

Post by Joel »

westingtyler wrote:hello. when loading an array of game objects or strings, should I use Load or Load Into? What is the functional difference?
Hi there,

ES3.Load creates a new instance of an object and loads the data into that. ES3.LoadInto does not create a new instance, and instead loads the data into the instance you give it.

With regards to your texture issue, this sounds like an issue which was resolved in the upcoming version. If you PM me your invoice number, I'll send you the update.

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