3D model to be destroyed

Discussion and help for Easy Save 3
Post Reply
KBTIT
Posts: 14
Joined: Mon Jul 17, 2023 5:24 am

3D model to be destroyed

Post by KBTIT »

Hi, I am very stumped by this issue.

Unit classes that do not inherit MonoBehaviour have a MapUnit class that inherits MonoBehaviour.
In other words

public class Unit {
[HideInInspector][ES3Serializable]
public MapUnit mapUnit;
}

Here, it would be best if just saving the Unit would also save the MapUnit, but that would always result in null, so we also saved the MapUnit object.
It is code like the following.

Code: Select all

void DoSave(){
        List<GameObject> mapUnits = new List<GameObject>(units.Count);
        foreach (var unit in units) mapUnits.Add(unit.mapUnit.gameObject);
        
        ES3.Save("mapUnits", mapUnits, file_name);
        ES3.Save("units", units, file_name);
}

void DoLoad(){
        var mapUnits = ES3.Load<List<GameObject>>("mapUnits", file_name);
        var units = ES3.Load<List<Unit>>("units", file_name);
}
In this process, the loaded unit is not null, probably the mapUnit object is successfully loaded.

However, the 3D model that mapunit had went wrong.
The left side of the following image shows the model in use, before saving.
The right is the state of the model when it is loaded. Only a little bit of equipment on his waist accounts for his being there.
model.png
model.png (431.58 KiB) Viewed 1066 times
This 3D model is maintained by MapUnit itself. Is this not a good idea?
However, I am using [ES3Serializable] and the model should be properly stored.
Is this a bad way to store the model you are using?

Code: Select all

public class MapUnit : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler {

    [ES3Serializable]
    [SerializeField] List<GameObject> UnitModels;
model_2.png
model_2.png (58.95 KiB) Viewed 1066 times
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: 3D model to be destroyed

Post by Joel »

Hi there,

This is likely because the entire GameObject is being saved, and some aspects such as the Mesh or Material isn't serializable at runtime. In this case you should usually follow the Saving and Loading Prefab Instances guide, and also add an ES3GameObject Component to your prefab (and it's children) and uncheck everything except the Transform.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
KBTIT
Posts: 14
Joined: Mon Jul 17, 2023 5:24 am

Re: 3D model to be destroyed

Post by KBTIT »

Are you referring to the "Choosing which Components are saved" section?
Also, What do you mean by ES3GameObject?
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: 3D model to be destroyed

Post by Joel »

Hi there,
Are you referring to the "Choosing which Components are saved" section?
The "In this case you should usually follow the Saving and Loading Prefab Instances guide" part is referring to the Saving and loading prefab instances section. The "also add an ES3GameObject Component to your prefab" is referring to the Choosing which Components are saved section.
Also, What do you mean by ES3GameObject?
This is explained in the Choosing which Components are saved section.

Just to double-check, are your UnitModels instances of prefabs?
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
KBTIT
Posts: 14
Joined: Mon Jul 17, 2023 5:24 am

Re: 3D model to be destroyed

Post by KBTIT »

This could be a translation issue.
Choosing which Components are saved" does not tell me the role of "ES3GameObject".

At any rate, I attached "ES3GameObject" to the MapUnit prefab and did Save and Load, but the problem did not improve.
ES3GameObject.png
ES3GameObject.png (34.93 KiB) Viewed 1046 times
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: 3D model to be destroyed

Post by Joel »

The ES3GameObject Component allows you to choose which Components are saved when you are saving that GameObject.
You can choose which Components are saved by adding an ES3GameObject Component to the GameObject and checking which Components you wish to be saved.
Please can you replicate your issue in a new project with a simple scene and private message it to me with instructions so I can see what is happening.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: 3D model to be destroyed

Post by Joel »

Thanks for sending that over, much appreciated.

You don't appear to have followed the Saving and Loading Prefab Instances section I mentioned above. I.e.
Capture.PNG
Capture.PNG (21.7 KiB) Viewed 1020 times
Once I did this for your MapUnitObject prefab your test scene worked fine.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply