Loading child objects
Re: Loading child objects
If I use es3.load<vector3> says can't convert to a quaternion, if I use es3.load<Quaternion> says can't convert to a vector 3
Ideally I need to save the child objects position and rotation only. Nothing else on the doors (and drawers).
Will see if I can make something later. Recovering from a fractured leg, first night back to work and in pain from a 10hr overnight shift and can't focus.
(only been walking without assistance for 3 days now)
Ideally I need to save the child objects position and rotation only. Nothing else on the doors (and drawers).
Will see if I can make something later. Recovering from a fractured leg, first night back to work and in pain from a 10hr overnight shift and can't focus.
(only been walking without assistance for 3 days now)
Re: Loading child objects
Unfortunately it's not possible for me to tell what is happening from what you've said. Please could you replicate this in a new script which I can drop into a new scene in a new project.
Re: Loading child objects
Sorry, as i mentioned long shifts. I do not have any scripts at the moment for this, was work in progress.
Going to try a little tonight or tomorrow, got sucked into a perforce repo that just wouldn't work right on my server.
I hate perforce but it really is one of the best for team version control once you get it set up correctly.
Going to try a little tonight or tomorrow, got sucked into a perforce repo that just wouldn't work right on my server.
I hate perforce but it really is one of the best for team version control once you get it set up correctly.
Re: Loading child objects
The main purpose here i am trying to avoid all these save as you go scripts (like activeobjects, destroyedObjects etc...) and save all at once.
So I am now trying to save the position (then rotation with a check box so I can say if it is a door or drawer) of interacted objects.
Drawers use position (slide in and out) and doors use rotation.
So I am trying to modify your positionsave script to create a dictionary or guid,transform.position then when they hit save save it. but I can't figure out how to load.
So I have on my Interactitem script a bool if true it fires off a methos on my position script which is on each scene object so it gets GUID. On my savescript I have a static dictionary the saveposition writes to.
Interactive door (this part works whenever I click to interact with it)
SavePositionScript
now on the savegame script
However I can't figure out how to load it back into the objects...
this
is on your original script but I can't for the life of me figure out how to get that dictionary out and loaded back onto the drawer objects...
So I am now trying to save the position (then rotation with a check box so I can say if it is a door or drawer) of interacted objects.
Drawers use position (slide in and out) and doors use rotation.
So I am trying to modify your positionsave script to create a dictionary or guid,transform.position then when they hit save save it. but I can't figure out how to load.
So I have on my Interactitem script a bool if true it fires off a methos on my position script which is on each scene object so it gets GUID. On my savescript I have a static dictionary the saveposition writes to.
Interactive door (this part works whenever I click to interact with it)
Code: Select all
Debug.Log("I am activating door ");
if (isDrawer)
{
GetComponent<SavePosition>().DoorPositionChange();
}
Code: Select all
public string guid = System.Guid.NewGuid().ToString();
[SerializeField] private bool savePositionInstead;
[SerializeField] public GameObject drawer = null;
public void DoorPositionChange()
{
if (savePositionInstead && drawer != null)
{
if (NotsoSave.doorValues.ContainsKey(guid))
{
NotsoSave.doorValues[guid] = drawer.transform.localPosition;
}
else
{
NotsoSave.doorValues.Add(guid, drawer.transform.localPosition);
}
}
}
Code: Select all
public static Dictionary<string, Vector3> doorValues
public void Save()
{
ES3.Save("Doors", doorValues);
}
this
Code: Select all
drawer.transform.localPosition = ES3.Load<Vector3>(guid, drawer.transform.localPosition);
Re: Loading child objects
Hi there,
To load the Dictionary you would do:
You would then need to assign your values back to the appropriate doors.
All the best,
Joel
To load the Dictionary you would do:
Code: Select all
doorValues = ES3.Load<Dictionary<string, Vector3>>("Doors");
All the best,
Joel
Re: Loading child objects
Would that be through the use of a for loop or foreach?
Re: Loading child objects
You could use either, but as that's a general coding question and a part of your logic rather than ours, I'm afraid I wouldn't be able to assist with that. I recommend Googling for "Looping over a Dictionary in C#" into Google for information on how to do that.
All the best,
Joel
Re: Loading child objects
I was already looking into those. I know that this part is not part of easy save, so hoping I can still get help.
First to test I used (I made a new method just for testing)
And I did get 2 different GUID and values, as expected.
My problem is how to load those into the objects.
I then got stuck at this point. I know this is wrong or at least a very slow method, but either way it did not fire off the debug.
First to test I used (I made a new method just for testing)
Code: Select all
void DrawerStates()
{
doorValues = ES3.Load<Dictionary<string, Vector3>>("Doors");
foreach(KeyValuePair<string, Vector3> kvp in doorValues)
{
Debug.Log("Key = {0} + Value = {1}" + kvp.Key + kvp.Value);
}
}
My problem is how to load those into the objects.
I then got stuck at this point. I know this is wrong or at least a very slow method, but either way it did not fire off the debug.
Code: Select all
void DrawerStates()
{
doorValues = ES3.Load<Dictionary<string, Vector3>>("Doors");
foreach(KeyValuePair<string, Vector3> kvp in doorValues)
{
var guid = kvp.Key;
if(guid == FindObjectOfType<SavePosition>().guid)
Debug.Log(gameObject.name);
// Debug.Log("Key = {0} + Value = {1}" + kvp.Key + kvp.Value);
}
}
Re: Loading child objects
You would need to use FindObjectsOfType rather than FindObjectOfType to get an array of all of the SavePosition objects, and then iterate through that array and find the one with that GUID and apply the data to that object.
Re: Loading child objects
Will give that a try.
It would be a pin in the ... but would creating a list of the drawers be quicker to reference than the entire scene?
I imagine it would.
It would be a pin in the ... but would creating a list of the drawers be quicker to reference than the entire scene?
I imagine it would.