hi, I have written the abilities of my character in separate classes, and I need to save some values of those classes, for example, the Health of the character.
so I write some codes in below, but it can't work. any help will be greatly appreciated.
protected override void WriteComponent(object obj, ES3Writer writer)
{
var instance = (Worker)obj;
writer.WritePrivateProperty("Level", instance);
writer.WriteProperty("Position", instance.transform.position, ES3Type_Vector3.Instance);
// how can I save other classes' data in this method?
writer.Write<int>("CurrentHealth", instance.GetComponent<Health>().CurrentHealth);
}
Could I save data in this way?
Re: Could I save data in this way?
Hi there,
ES3Types are only intended to write classes and their variables. Instead you should use multiple ES3.Save or ES3File.Save calls to save the classes separately.
However, if you did wish to try to use ES3Types in this way, I see no reason for the code you're posting to not work. Please could you let me know the error you are getting?
All the best,
Joel
ES3Types are only intended to write classes and their variables. Instead you should use multiple ES3.Save or ES3File.Save calls to save the classes separately.
However, if you did wish to try to use ES3Types in this way, I see no reason for the code you're posting to not work. Please could you let me know the error you are getting?
All the best,
Joel
-
- Posts: 11
- Joined: Sun Jul 29, 2018 3:25 am
Re: Could I save data in this way?
I changed the code in this way, it works right now. thanks.
writer.WritePrivateField("CurrentHealth", instance.GetComponent<Health>());
writer.WritePrivateField("CurrentHealth", instance.GetComponent<Health>());