Array field stored by reference

Discussion and help for Easy Save 3
Post Reply
zalos
Posts: 2
Joined: Sun Jan 03, 2021 2:12 am

Array field stored by reference

Post by zalos »

I have a configuration with a list of node configs in it, so:

Code: Select all

public class SolarSystemConfig 
{
	public int Star;
	public List<SolarPathNode> Paths;
	public List<GameObject> PathNodes;
}
Solar path node is a component on a gameobject. When I save this individually it works, but when it is in a list, it does not.

Code: Select all

//Saves but node data in list is all default
ES3.Save(saveName, _currentConfig);

//Works - this is an individual node game object
ES3.Save("nodeTest", _currentConfig.PathNodes[3]);

//Works - this is an individual Solar node component
ES3.Save("solarNodeTest", ChosenPath[3]);

public class SolarPathNode : MonoBehaviour
{
	public int CordsX;
	public int CordsY;
	public GameObject ZonePrefab;
	public ScenarioType TypeChosen;
	public string ScenarioName;
}
Do I need to save every item individually or is there a different way to save this as a list?
User avatar
Joel
Moodkie Staff
Posts: 4852
Joined: Wed Nov 07, 2012 10:32 pm

Re: Array field stored by reference

Post by Joel »

Hi there,

I've moved your question to a separate thread as the Example Request thread is for requesting examples rather than for technical questions regarding your specific project.

Regarding your question, fields and items in arrays which are fields are stored by reference, which is why you're getting the behaviour you're experiencing. If you want to store the array and its contents by value you should save it separately. I.e.

Code: Select all

ES3.Save("solarNodeTest", ChosenPath);
All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
zalos
Posts: 2
Joined: Sun Jan 03, 2021 2:12 am

Re: Array field stored by reference

Post by zalos »

Thank you, that's what I am doing but wanted to make sure that was the correct approach. Thanks!!
Post Reply