mesh is null

Discussion and help for Easy Save 3
Post Reply
a87645507
Posts: 5
Joined: Mon Jul 04, 2022 7:15 am

mesh is null

Post by a87645507 »

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
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: mesh is null

Post by Joel »

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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
a87645507
Posts: 5
Joined: Mon Jul 04, 2022 7:15 am

Re: mesh is null

Post by a87645507 »

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
Is that what you're saying?

Code: Select all

foreach (MeshFilter item in _model.GetComponentsInChildren<MeshFilter>())
        {
            ES3.Save(item.name,item.mesh);
        }
This will get stuck
Last edited by a87645507 on Tue Jan 17, 2023 6:11 am, edited 1 time in total.
a87645507
Posts: 5
Joined: Mon Jul 04, 2022 7:15 am

Re: mesh is null

Post by a87645507 »

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
I try to do that

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!");
    }
Doing this takes up a lot of CPU and can get stuck
a87645507
Posts: 5
Joined: Mon Jul 04, 2022 7:15 am

Re: mesh is null

Post by a87645507 »

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
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.

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!");
    }
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: mesh is null

Post by Joel »

Hi there,
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.
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.

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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply