Not saving custom class components

Discussion and help for Easy Save 3
Post Reply
bbjones
Posts: 3
Joined: Sat May 15, 2021 10:04 pm

Not saving custom class components

Post by bbjones »

Hi,
I'm new to easysave so may be missing something obvious but when I add a custom script to a game object and save it, nothing about the script is saved.

I made a new test scene with ES3 manager.
I have tried changing settings for Save Gameobject Children and serialize by Ref And Value but no difference.
I create an empty game object, attach my custom script.
Then click a button to fire off this code:

Code: Select all

        for (int i = 0; i < this.ObjectsToSave.Count; i++)
		{
            this.saveNames.Add(System.Guid.NewGuid().ToString() + ".json");
            ES3.Save(this.saveNames[i], this.ObjectsToSave[i], this.saveNames[i]);
        }
It works, I get a new save file for each gameobject in the list, the contents however are only showing native Unity gameobject values and structure.
It will show child objects etc, but nothing about any custom scripts.
I have searched the forums and documentation and don't see anything obvious about this and feel like I must be missing something obvious since custom scripts will be on pretty much everything in a game.

One example of my empty GO save file:

Code: Select all

{
	"b48d835f-9896-4e47-bb8a-4c6af22f5dd7.json" : {
		"__type" : "GameObject",
		"value" : {
			"_ES3Ref" : "6705505823549809242",
			"transformID" : 1077788400736667770,
			"layer" : 0,
			"tag" : "Untagged",
			"name" : "LG_GameObject",
			"hideFlags" : 0,
			"active" : true,
			"children" : [
				
			],
			"components" : [
				{
					"__type" : "Transform",
					"_ES3Ref" : "1077788400736667770",
					"goID" : "6705505823549809242",
					"parent" : null,
					"localPosition" : {
						"x" : 80,
						"y" : 416,
						"z" : 0
					},
					"localRotation" : {
						"x" : 0,
						"y" : 0,
						"z" : 0,
						"w" : 1
					},
					"localScale" : {
						"x" : 1,
						"y" : 1,
						"z" : 1
					}
				}
			]
		}
	}
}
The goal I'm after is the player creates a new combination of gameobjects and components based on prefabs and customizable settings, which I then want to save as a blueprint and destroy the original from the in-game scene. Then later the player can load blueprints back into any scene or game session.
The blueprint object will be much more complicated than my empty test above, but I'm just trying to prove the basic concept works first.

The custom class derives from mono behaviour and contains native public fields like strings and booleans.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Not saving custom class components

Post by Joel »

Hi there,

This is covered in the Saving and Loading GameObjects guide:
https://docs.moodkie.com/easy-save-3/es ... s-prefabs/

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
bbjones
Posts: 3
Joined: Sat May 15, 2021 10:04 pm

Re: Not saving custom class components

Post by bbjones »

Joel wrote: Sun May 16, 2021 8:37 am Hi there,

This is covered in the Saving and Loading GameObjects guide:
https://docs.moodkie.com/easy-save-3/es ... s-prefabs/

All the best,
Joel
Are you saying I have to decorate and go through steps for every class/script in my game even when they are made up of supported types?
If so why not say that instead of RTFM? I read the docs and it wasn't clear to me what I had to do hence the question.

By the way, the link to these forums from your website links to the ES2 legacy forum.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Not saving custom class components

Post by Joel »

Hi there,
If so why not say that instead of RTFM? I read the docs and it wasn't clear to me what I had to do hence the question.
I linked to the docs because my response would have been repeating what was written in here, and it also contains information on how you go about adding it as a supported type. It also helps if other people come across this thread. Please let me know if there's anything unclear about what is written in there and I'll try to clarify.
Are you saying I have to decorate and go through steps for every class/script in my game even when they are made up of supported types?
That is correct. Just because the fields of a type are supported, it doesn't mean that type will be serialisable at runtime. If we didn't have this constraint, you would need to serialise every Component on the GameObject, including those which cannot be serialised at runtime. This would lead to errors. Hope this helps make things a bit clearer.
By the way, the link to these forums from your website links to the ES2 legacy forum.
Thanks for the heads-up. I'll see about getting this resolved in the next documentation update we push to the server.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
bbjones
Posts: 3
Joined: Sat May 15, 2021 10:04 pm

Re: Not saving custom class components

Post by bbjones »

I suppose it just seemed to be glossed over that the core of what EasySave does will not do what I imagine a lot of people need without a bunch of work repeated hundreds of times, which is to save their custom scripts. That doesn't come across as "easy" to me. So perhaps the name of your asset set my expectations in a way that your documentation did not correct.

You pointed me to the documentation that links to the documentation that is relevant. Perhaps point to the documentation that is relevant in the first place.

This line in particular:
"Components on the Natively-supported types list, or those which have been manually supported using an ES3Type."

Could perhaps change to something like this:
"EasySave supports native components such as these (link). For all other classes/scripts/components that you create and want to save, you need to follow this guide for each one. You need to do the same for all classes/scripts/components that other 3rd party assets created."

Or am I still miss-understanding what I have to do?

Please note I'm also trying to be thorough and clear to help other people with the same or similar question, because I did search the forums and mostly saw you posting links to the documentation with no further clarification, which wasn't helpful for me.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Not saving custom class components

Post by Joel »

Thanks for the feedback, much appreciated. If this becomes an issue then we'll definitely look into changing the terminology used.

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