ES3Prefab and ES3AutoSave for Prefab Variants

Discussion and help for Easy Save 3, The Complete Save Game & Data Serializer System for the Unity Engine
yimingt
Posts: 33
Joined: Fri Apr 30, 2021 3:07 am

ES3Prefab and ES3AutoSave for Prefab Variants

Post by yimingt »

Right now I have prefab variants like so:
  • GridItem (Saves active state and position)
    • WallItem (Saves active state, position, additional Health component)
      • BrickWall (Functionally same as WallItem just a difference in visuals)
At which stage of the prefab should I be applying the ES3Prefab and ES3AutoSave?

Can I have both ES3Prefab and ES3AutoSave on the GridItem but then modify the WallItem's ES3AutoSave to include the Health component?
User avatar
Joel
Moodkie Staff
Posts: 5037
Joined: Wed Nov 07, 2012 10:32 pm

Re: ES3Prefab and ES3AutoSave for Prefab Variants

Post by Joel »

Hi there,

You can add the ES3AutoSave Component whenever you like and change what is saved in the Auto Save window whenever you like.

You can add the ES3Prefab Component whenever you like, but be aware if you make a variant it will have the same prefab ID as it's parent, so you will need to open the Advanced Settings foldout of the ES3Prefab Component and give it a unique prefab ID.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
yimingt
Posts: 33
Joined: Fri Apr 30, 2021 3:07 am

Re: ES3Prefab and ES3AutoSave for Prefab Variants

Post by yimingt »

give it a unique prefab ID
Is there a way to have ES3 generate the ID for me?
User avatar
Joel
Moodkie Staff
Posts: 5037
Joined: Wed Nov 07, 2012 10:32 pm

Re: ES3Prefab and ES3AutoSave for Prefab Variants

Post by Joel »

yimingt wrote: Mon Nov 04, 2024 10:28 am
give it a unique prefab ID
Is there a way to have ES3 generate the ID for me?
Unity provides us with no way of reliably determining when a prefab variant has been created, so this isn't possible for us to automate.
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
yimingt
Posts: 33
Joined: Fri Apr 30, 2021 3:07 am

Re: ES3Prefab and ES3AutoSave for Prefab Variants

Post by yimingt »

Would a warning appear if the prefab ID were similar to another ES3Prefab? I'm worried about duplicate Prefab IDs.
User avatar
Joel
Moodkie Staff
Posts: 5037
Joined: Wed Nov 07, 2012 10:32 pm

Re: ES3Prefab and ES3AutoSave for Prefab Variants

Post by Joel »

yimingt wrote: Tue Nov 05, 2024 3:04 am Would a warning appear if the prefab ID were similar to another ES3Prefab? I'm worried about duplicate Prefab IDs.
It wouldn't because there would be no way for Easy Save to know that it was a duplicate ID (otherwise we'd be able to automatically change it).
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
yimingt
Posts: 33
Joined: Fri Apr 30, 2021 3:07 am

Re: ES3Prefab and ES3AutoSave for Prefab Variants

Post by yimingt »

Perhaps there could be a feature for the ES3ReferenceManager to iterate through the ES3Prefab list and output those that are duplicate. Wouldn't solve in creating an ID that is unique but at least we would know of a duplication issue happening.
User avatar
Joel
Moodkie Staff
Posts: 5037
Joined: Wed Nov 07, 2012 10:32 pm

Re: ES3Prefab and ES3AutoSave for Prefab Variants

Post by Joel »

yimingt wrote: Wed Nov 06, 2024 1:45 am Perhaps there could be a feature for the ES3ReferenceManager to iterate through the ES3Prefab list and output those that are duplicate. Wouldn't solve in creating an ID that is unique but at least we would know of a duplication issue happening.
We wouldn't do this automatically as there are situations where it's useful to have the same prefab ID for different prefabs. However, the following Editor script should do this for the active scene:

Code: Select all

using UnityEditor;
using UnityEngine;

public class CheckPrefabDuplicates : MonoBehaviour
{
    [MenuItem("Tools/Easy Save 3/Check for duplicate prefab IDs")]
    private static void Run()
    {
	var mgr = GameObject.Find("Easy Save 3 Manager").GetComponent<ES3ReferenceMgr>();
	
	Debug.Log("Prefab duplicate check started");
	
        foreach (var prefab in mgr.prefabs)
        	foreach(var prefab2 in mgr.prefabs)
        		if(prefab != prefab2 && prefab.prefabId == prefab2.prefabId)
        			Debug.LogWarning($"Prefab {prefab2.gameObject.name} with ID {prefab2.prefabId} has same ID as Prefab {prefab.gameObject.name}", prefab2);
        			
        Debug.Log("Prefab duplicate check finished");
    }
}
All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
yimingt
Posts: 33
Joined: Fri Apr 30, 2021 3:07 am

Re: ES3Prefab and ES3AutoSave for Prefab Variants

Post by yimingt »

situations where it's useful to have the same prefab ID for different prefabs
That's interesting. When would doing such a thing be useful? Wouldn't having the same ID potentially cause it to spawn the undesired prefab?
User avatar
Joel
Moodkie Staff
Posts: 5037
Joined: Wed Nov 07, 2012 10:32 pm

Re: ES3Prefab and ES3AutoSave for Prefab Variants

Post by Joel »

yimingt wrote: Wed Nov 06, 2024 10:07 am
situations where it's useful to have the same prefab ID for different prefabs
That's interesting. When would doing such a thing be useful? Wouldn't having the same ID potentially cause it to spawn the undesired prefab?
The most common situation is when you need to save a prefab instance, but this prefab needs to be different in different scenes. And then there's a less common situation during development where you might not have decided on which prefab you will be using for the release so you will have multiple candidate prefabs which need to have the same ID as you're bundling save data with the build (this relies on ordering the prefab list).

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