- Home /
how can i pass the variable values of my serializeable class into another class that have the same variables?,How can i copy the values of a serializable class into another class
i have a class(serialize-able) where i save my datas and i want to put it's values to a temporary class where i'm gonna manipulate them there.
Answer by melsy · Feb 02, 2018 at 01:26 PM
Don's create a dummy class to manipulate the variables. Create a public static reference to the class and manipulate the vars directly.
[Serializable]
public class SaveData
{
public static SaveVariables saveVars = new SaveVariables();
// This class will have the save and load methods
// This class will house all the vars that will be saved.
[Serializable]
public class SaveVariables
{
// When the save file is deleted and recreated, These values will be defaulted.
public const string name = "Jones";
public int var1 = 17;
public bool var2 = false;
public float var3 = .5f;
}
}
Then to call a variable in any other script call SaveData.saveVars.var = value; at number will be restored. When you save that number will be saved. and upon loading th
Your answer
Follow this Question
Related Questions
Is it possible to create a custom gettter/setter on SerializedProperty ? 0 Answers
Serialized Fields go bye bye on Android 0 Answers
How do I save scripts as variables in the inspector? 0 Answers
EndOfStreamException : Failed to read past end of stream 1 Answer
Serialization and Object references 0 Answers