Thanks for the questions.
In your case it would be better to create a data model just for position, health and enemy data at all, something like this:
public class EnemyData {
public Vector3 position;
public float health;
// add more properties here
}
Which you can extend it for other enemies:
public class OtherEnemyData : EnemyData {
public int headHealth;
public int bodyHealth;
}
Then save and load it like this:
// Loop through your enemies and fetch the data and fill this list
List<EnemyData> enemiesData = new List<EnemyData>();
// Loop here ...
// Save the data
await SaveSystemAPI.SaveAsync("enemies.dat", enemies);
// Load back the data
List<EnemyData> enemiesData = await SaveSystemAPI.LoadAsync<List<EnemyData>>("enemies.dat");
// Then instantiate enemies based on the EnemyData type maybe?
if (enemiesData[i] is OtherEnemyData) {
// Instanitate otherenemy prefab ...
}
This is the solution I’ve got in my mind so far, but I’m pretty sure you might be able to do it simpler or better anyway.
Or maybe instead of doing it all, just create an object converter for Enemy component and get a list of your enemies and save it like this:
Enemy[] enemies = FindObjectsOfType<Enemy>();
// Save the enemies component data which is managed by its own Object Json Converter
await SaveSystemAPI.SaveAsync("enemies.dat", enemies);
// Load the data back into enemies (components)
// Use Load if the enemies (components) are referenced by Scene Reference Resolver, otherwise use LoadInto to directly load the data into them
await SaveSystemAPI.LoadAsync("enemies.dat");
await SaveSystemAPI.LoadIntoAsync("enemies.dat", enemies);
Learn more about Creating a Custom Object Converter.
And for your second question, that would be a good addition, but for now, I think you can extend the AutoSave class to add this event or just modify the AutoSave script.
But I’ll try to include this event in the next update.
Learn more about sceneLoaded event.
Thanks 