I load the model externally to this GameObject. Use es3.save<GameObject>(ABC,GameObject). Use es3.load<GameObject>(ABC).
Only ABC name, mesh is null.
What should I do? Please write the code in detail once
mesh is null
Re: mesh is null
Hi there,
Fields of UnityEngine.Objects are saved by reference. Because your model is generated at runtime, a reference to it will not exist between sessions. Instead you would need to save your Mesh using a separate ES3.Save call to ensure that it is saved by value and load it before loading anything which references it, assuming the Mesh can be serialized at runtime.
All the best,
Joel
Fields of UnityEngine.Objects are saved by reference. Because your model is generated at runtime, a reference to it will not exist between sessions. Instead you would need to save your Mesh using a separate ES3.Save call to ensure that it is saved by value and load it before loading anything which references it, assuming the Mesh can be serialized at runtime.
All the best,
Joel
Re: mesh is null
Is that what you're saying?Joel wrote: ↑Mon Jan 16, 2023 10:19 am Hi there,
Fields of UnityEngine.Objects are saved by reference. Because your model is generated at runtime, a reference to it will not exist between sessions. Instead you would need to save your Mesh using a separate ES3.Save call to ensure that it is saved by value and load it before loading anything which references it, assuming the Mesh can be serialized at runtime.
All the best,
Joel
Code: Select all
foreach (MeshFilter item in _model.GetComponentsInChildren<MeshFilter>())
{
ES3.Save(item.name,item.mesh);
}
Last edited by a87645507 on Tue Jan 17, 2023 6:11 am, edited 1 time in total.
Re: mesh is null
I try to do thatJoel wrote: ↑Mon Jan 16, 2023 10:19 am Hi there,
Fields of UnityEngine.Objects are saved by reference. Because your model is generated at runtime, a reference to it will not exist between sessions. Instead you would need to save your Mesh using a separate ES3.Save call to ensure that it is saved by value and load it before loading anything which references it, assuming the Mesh can be serialized at runtime.
All the best,
Joel
Code: Select all
IEnumerator tyr(GameObject _model)
{
for (int i = 0; i < _model.transform.childCount; i++)
{
yield return new WaitForEndOfFrame();
ES3.Save<Mesh>(_model.transform.GetChild(i).GetComponent<MeshFilter>().name, _model.transform.GetChild(i).GetComponent<MeshFilter>().mesh);
}
Debug.Log("Success!");
}
Re: mesh is null
I can successfully load mesh in this way. However, both save and load take up a lot of CPU, and it takes more than 5 minutes to load. There are 400 sub-objects under GameObject. Using Dictionary will cause the computer to get stuck .Using es3.save or es3.load directly will also cause the computer to get stuck.I'm the webgl platform.Joel wrote: ↑Mon Jan 16, 2023 10:19 am Hi there,
Fields of UnityEngine.Objects are saved by reference. Because your model is generated at runtime, a reference to it will not exist between sessions. Instead you would need to save your Mesh using a separate ES3.Save call to ensure that it is saved by value and load it before loading anything which references it, assuming the Mesh can be serialized at runtime.
All the best,
Joel
Code: Select all
IEnumerator tyr(GameObject _model)
{
Dictionary<string, Mesh> ty = new Dictionary<string, Mesh>();
for (int i = 0; i < _model.transform.childCount; i++)
{
ty.Add(_model.transform.GetChild(i).GetComponent<MeshFilter>().name, _model.transform.GetChild(i).GetComponent<MeshFilter>().mesh);
}
yield return new WaitForSeconds(0.5f);
ES3.Save(_model.name + "mesh", ty);
Debug.Log("Success!");
}
Re: mesh is null
Hi there,
However, it sounds like you've previously saved each Mesh to a previous key and I suspect that these keys are still in your save file, so it's likely a particularly large save file at this point.
First I recommend deleting your save data entirely. You can use ES3.DeleteFile to do this, or PlayerPrefs.DeleteAll as PlayerPrefs is used as the storage location on WebGL. If this doesn't resolve your issue please could you replicate it in a new project with a simple scene and private message it to me with instructions.
All the best,
Joel
This could be for two reasons. The first is that Meshes are inherently expensive items to serialize, which is unavoidable if you indeed need to save your Mesh by value.I can successfully load mesh in this way. However, both save and load take up a lot of CPU, and it takes more than 5 minutes to load.
However, it sounds like you've previously saved each Mesh to a previous key and I suspect that these keys are still in your save file, so it's likely a particularly large save file at this point.
First I recommend deleting your save data entirely. You can use ES3.DeleteFile to do this, or PlayerPrefs.DeleteAll as PlayerPrefs is used as the storage location on WebGL. If this doesn't resolve your issue please could you replicate it in a new project with a simple scene and private message it to me with instructions.
All the best,
Joel