GeneratePrefabReferences creates massive prefabs

Discussion and help for Easy Save 3
Post Reply
FredTuna
Posts: 20
Joined: Sat Aug 10, 2019 3:16 pm

GeneratePrefabReferences creates massive prefabs

Post by FredTuna »

It seems that Unity's CollectDependencies keeps adding more and more dependencies over time and this makes it so that the serialized localRefs dictionary in ES3Prefab keeps growing to the point of making massive prefab assets. It looks like it may be due to ES3PRefab's localRefs references being included in CollectDependencies which means that it keeps adding more and more references every time that GeneratePrefabReferences is called.
If tested that by clearing localRefs before calling CollectDependencies and the number of dependencies is then always the same (and of reasonable size). This would work but then that means that my prefab assets keep getting modified because the localRefs dictionary changes (even if it contains the same items, these could be in a different order).

Is there a way to ignore the localRefs references in CollectDependencies or to otherwise generate prefab references slightly differently to avoid this issue? I guess I could manually go through every property and build the localRefs that way (similar to this but without being recursive https://forum.unity.com/threads/editoru ... ch.128948/). Speaking of recursive, is localRefs meant to keep references of references or just direct references? It seems to me that it would be the latter.

Any help is appreciated!

Thanks!

- Fred
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: GeneratePrefabReferences creates massive prefabs

Post by Joel »

Hi Fred,

localRefs only stores references to objects, so it's strange that this is increasing the size of the prefab.

When localRefs is processed, localRefs is first cleared entirely and then CollectDependencies is used to find all dependencies, so it's strange that it is increasing in size each time. Would you be able to create a very basic project which replicates this and private message it to me?

Just to clarify, is this a prefab in Assets or is this a prefab instance in a scene? The ES3Prefab script should only be used for prefabs in Assets, not prefab instances in scenes.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
FredTuna
Posts: 20
Joined: Sat Aug 10, 2019 3:16 pm

Re: GeneratePrefabReferences creates massive prefabs

Post by FredTuna »

Hey Joel,
thanks for the reply.

This is on a prefab asset yes.

As for the localRefs being cleared, I don't see where this is done? I had to manually call

Code: Select all

localRefs.Clear();
before calling CollectDependencies() and that changes the number of dependencies significantly (because localRefs grew over time). Maybe I modified the code somewhere that had the effect of not clearing localRefs before CollectDependencies but I don't think so.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: GeneratePrefabReferences creates massive prefabs

Post by Joel »

Hi Fred,

My apologies, I was certain our code creates a new Dictionary and then performs a diff to only add the current dependencies. However, looking at our repo it looks like we've not used this method since the beta because it triggered Unity's 'black text' bug when it encounters a UI.Text Component.

However, because we're generating prefab references in a different event, this won't be a problem. I'll revert back the code and perform some tests to check that this is the case, and PM the update to you.

Just a quick note: clearing localRefs entirely will generate new reference IDs, which will invalidate any save data stored prior to it being cleared, so I don't recommend doing this. However, the update I'll send you will maintain existing IDs.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
FredTuna
Posts: 20
Joined: Sat Aug 10, 2019 3:16 pm

Re: GeneratePrefabReferences creates massive prefabs

Post by FredTuna »

Oh good to know. I thought the id was assigned when the ES3Prefab component was instantiated and then the localrefs was just a list of those ids.
Regardless, I appreciate you solving this! I'll be waiting for your PM :)
Post Reply