Auto add references when put in certain folders?

Discussion and help for Easy Save 3
poptarts4444
Posts: 18
Joined: Sat Jul 15, 2023 2:58 am

Auto add references when put in certain folders?

Post by poptarts4444 »

So my game doesn't need much saved besides SOs and other referenced assets. So I have the auto-add things from the scene turned off for my Easy Save Manager.

I was wondering if there was a way to setup something where whenever I created a new asset in a certain folder in my project, it would add it to the Reference Manager.

For example, I have food SOs. Their data is stuff like name, cost, mesh, material, etc. I make new ones all the time. The player has an inventory of sorts that gets filled with the food they have purchased and picked up. That list needs to get saved. So In order for it to save and load, those food SO items need to be in the reference section on the Manager. I'd rather not add them one by one every time I add a new one. Is there any way to automate this?

Thanks
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Auto add references when put in certain folders?

Post by Joel »

Hi there, and thanks for getting in contact.

You can ask Easy Save to watch folders for references by the path (relative to the projects folder, e.g. Assets/MyFolder/) to the Reference Folders list in Tools > Easy Save 3 > Settings. However, this is part of the automatic reference updating system which you've disabled.

The only alternative would be to write your own Editor script which calls the manager's hidden AddDependenciesFromFolders() method in order for this to be called, perhaps using PlayModeStateChanged and PlayModeStateChange.ExitingEditMode to ensure that it's called automatically before you enter playmode.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
poptarts4444
Posts: 18
Joined: Sat Jul 15, 2023 2:58 am

Re: Auto add references when put in certain folders?

Post by poptarts4444 »

Joel wrote: Sat Jul 15, 2023 8:32 am Hi there, and thanks for getting in contact.

You can ask Easy Save to watch folders for references by the path (relative to the projects folder, e.g. Assets/MyFolder/) to the Reference Folders list in Tools > Easy Save 3 > Settings. However, this is part of the automatic reference updating system which you've disabled.

The only alternative would be to write your own Editor script which calls the manager's hidden AddDependenciesFromFolders() method in order for this to be called, perhaps using PlayModeStateChanged and PlayModeStateChange.ExitingEditMode to ensure that it's called automatically before you enter playmode.

All the best,
Joel
ah ok interesting. So if I turn the auto update back on, does too many things inside the reference manager slow the game down at all?
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Auto add references when put in certain folders?

Post by Joel »

The reference manager just keeps references to things which are already in your scene (or things you've told it to keep references to) so that it can assign a persistent ID to them. It uses a Dictionary underneath so the number of references won't affect performance.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
poptarts4444
Posts: 18
Joined: Sat Jul 15, 2023 2:58 am

Re: Auto add references when put in certain folders?

Post by poptarts4444 »

Joel wrote: Sat Jul 15, 2023 8:32 am Hi there, and thanks for getting in contact.

You can ask Easy Save to watch folders for references by the path (relative to the projects folder, e.g. Assets/MyFolder/) to the Reference Folders list in Tools > Easy Save 3 > Settings. However, this is part of the automatic reference updating system which you've disabled.

The only alternative would be to write your own Editor script which calls the manager's hidden AddDependenciesFromFolders() method in order for this to be called, perhaps using PlayModeStateChanged and PlayModeStateChange.ExitingEditMode to ensure that it's called automatically before you enter playmode.

All the best,
Joel
How do I access this AddDependenciesFromFolders() method? Can't find it anywhere? Even did CTRL + F for whole project.
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Auto add references when put in certain folders?

Post by Joel »

Hi there,

Are you using the latest version of Easy Save?

Also be aware that the method won't come up in code completion because as mentioned previously, it's hidden.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
poptarts4444
Posts: 18
Joined: Sat Jul 15, 2023 2:58 am

Re: Auto add references when put in certain folders?

Post by poptarts4444 »

Joel wrote: Mon Jul 17, 2023 7:52 am Hi there,

Are you using the latest version of Easy Save?

Also be aware that the method won't come up in code completion because as mentioned previously, it's hidden.

All the best,
Joel
I guess how do you unhide it haha?
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Auto add references when put in certain folders?

Post by Joel »

Hi there,

It's hidden but that doesn't mean you can't use the method, it just means it won't appear in code completion. So for example this code would work, even though the method doesn't appear in code completion:

Code: Select all

GameObject.Find("Easy Save 3 Manager").GetComponent<ES3ReferenceMgr>().AddDependenciesFromFolders();
If that doesn't work for you then I would double check you're using the latest version of Easy Save.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
poptarts4444
Posts: 18
Joined: Sat Jul 15, 2023 2:58 am

Re: Auto add references when put in certain folders?

Post by poptarts4444 »

Joel wrote: Mon Jul 17, 2023 2:49 pm Hi there,

It's hidden but that doesn't mean you can't use the method, it just means it won't appear in code completion. So for example this code would work, even though the method doesn't appear in code completion:

Code: Select all

GameObject.Find("Easy Save 3 Manager").GetComponent<ES3ReferenceMgr>().AddDependenciesFromFolders();
If that doesn't work for you then I would double check you're using the latest version of Easy Save.

All the best,
Joel
So I got this working, but PlayModeStateChange.ExitingEditMode isn't being called lol. All the other changes are, but not that one... So I gotta figure that out. Thanks for the help though!
poptarts4444
Posts: 18
Joined: Sat Jul 15, 2023 2:58 am

Re: Auto add references when put in certain folders?

Post by poptarts4444 »

Joel wrote: Mon Jul 17, 2023 2:49 pm Hi there,

It's hidden but that doesn't mean you can't use the method, it just means it won't appear in code completion. So for example this code would work, even though the method doesn't appear in code completion:

Code: Select all

GameObject.Find("Easy Save 3 Manager").GetComponent<ES3ReferenceMgr>().AddDependenciesFromFolders();
If that doesn't work for you then I would double check you're using the latest version of Easy Save.

All the best,
Joel
So actually it seems that the references added aren't saved. Like when I open another scene and go back to the other, all the references are gone.

Code: Select all

[InitializeOnLoad]
public class EasySave3ManagerEditorFolderWatch
{
    static EasySave3ManagerEditorFolderWatch()
    {
        EditorApplication.playModeStateChanged += StateChanged;
    }

    static void StateChanged(PlayModeStateChange state)
    {
        if (state == PlayModeStateChange.ExitingEditMode)
        {
            ES3ReferenceMgr es3 = GameObject.Find("Easy Save 3 Manager").GetComponent<ES3ReferenceMgr>();

            es3?.AddDependenciesFromFolders();
            //es3.
        }
    }
}
Post Reply