Unique ID

Discussion and help for Easy Save 3
Post Reply
nFighter
Posts: 52
Joined: Thu Apr 12, 2018 7:15 am

Unique ID

Post by nFighter »

Hey! I'm not using any autosave features, but I'm trying to save some custom data for particular objects in a specific scene. Let's say it's a "Point Of Interest" GameObjects that must save just one bool value "ifVisited". What is the best/correct method to save and load it? I thought about something like
1. Generate a unique ID for each GameObject I want to save
2. Save a pair: ID + boolValue in a file
3. On scene load read from a file and assign boolValue for each GameObject with a certain ID

BUT! I'm pretty sure it's a task that EasySave probably already solve for me in some way. Like, do I really need to invent my own unique ID generation or EasySave already have something?
nFighter
Posts: 52
Joined: Thu Apr 12, 2018 7:15 am

Re: Unique ID

Post by nFighter »

For now, I'm thinking about generating an ID with unity's native GUID like this

Code: Select all

public string _id = System.Guid.NewGuid().ToString();
but is it a legit move? Can I save references to GameObjects in a scene in some other way?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Unique ID

Post by Joel »

Hi there,

Components are saved by reference, so you can simply save the Component containing your bool value and Easy Save will do the work for you (it will prompt you to add an Easy Save 3 Manager to your scene if you don't already have one).

I.e.

Code: Select all

ES3.Save("myComponent", component);

Code: Select all

// This will load the Component by reference, assuming the Component isn't generated at runtime.
ES3.Load<ComponentType>("myComponent");

Code: Select all

// Alternatively you can tell it what Component you want to load the data into.
ES3.Load<ComponentType>("myComponent"); // This will load the Component by reference.
If there are fields which you don't want to be saved, you can mark them with the [ES3NonSerialized] attribute or go to Tools > Easy Save 3 > Types, and select which fields you want to be saved for the type there.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
nFighter
Posts: 52
Joined: Thu Apr 12, 2018 7:15 am

Re: Unique ID

Post by nFighter »

Oh, nice! It makes everything easier!
Post Reply