ArgumentException when deleting a component in a prefab

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

ArgumentException when deleting a component in a prefab

Post by FredTuna »

Hey,

I get this exception when deleting a component in prefabs that have an ES3Prefab component on it.

Code: Select all

ArgumentException: An item with the same key has already been added. Key: null
System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <a8ed250850854b439cedc18931a314fe>:0)
System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <a8ed250850854b439cedc18931a314fe>:0)
ES3Internal.ES3SerializableDictionary`2[TKey,TVal].OnAfterDeserialize () (at Assets/Plugins/Easy Save 3/Scripts/ES3SerializableDictionary.cs:42)
UnityEditor.EditorApplication:Internal_CallUpdateFunctions() (at ?)
It doesn't seem to be causing issues otherwise.

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

Re: ArgumentException when deleting a component in a prefab

Post by Joel »

Hi there,

I don't appear to be able to replicate this at my end. Would you be able to provide more detail about how and when you're deleting the Component? i.e. is it a prefab in a scene or in Assets? Are you pressing Delete in the Editor or are you deleting from a script? Does the error occur immediately?

If it's easier, feel free to PM me a basic project and instructions which replicate this.

Also as always, it's worth checking that you're on the very latest version of Easy Save.

All the best,
Joel
Joel @ Moodkie Interactive
Twitter - Unity

FredTuna
Posts: 20
Joined: Sat Aug 10, 2019 3:16 pm

Re: ArgumentException when deleting a component in a prefab

Post by FredTuna »

Hi Joel,

this happens every time in my project when I do this:

1) Open prefab asset containing an ES3Prefab component (not just select it but open the prefab by double clicking it)
2) Right click on any component in the the inspector and select Remove Component

The error appears immediately in the console.

Hopefully that helps. My project is too big to share but I could try reproducing in an empty project if needed.

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

Re: ArgumentException when deleting a component in a prefab

Post by Joel »

Hi there,

I still don't appear to encounter any errors when doing this. If you could PM me a minimal project which replicates this, that would be greatly appreciated.

All the best,
Joel
Joel @ Moodkie Interactive
Twitter - Unity

FredTuna
Posts: 20
Joined: Sat Aug 10, 2019 3:16 pm

Re: ArgumentException when deleting a component in a prefab

Post by FredTuna »

This may be related:

I have a few prefabs and scenes which contain localRefs or idRefs with null guids like this:

Code: Select all

    - {fileID: 2, guid: 00000000000000000000000000000000, type: 0}
    - {fileID: 2, guid: 00000000000000000000000000000000, type: 0}
    - {fileID: 2, guid: 00000000000000000000000000000000, type: 0}
I've tried refreshing references and opening prefabs and saving them but htese invalid guids remain and trigger exceptions when loading :

Code: Select all

ArgumentNullException: Value cannot be null.
Parameter name: key
System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <599589bf4ce248909b8a14cbe4a2034e>:0)
System.Collections.Generic.Dictionary`2[TKey,TValue].set_Item (TKey key, TValue value) (at <599589bf4ce248909b8a14cbe4a2034e>:0)
ES3Internal.ES3ReferenceMgrBase.Add (UnityEngine.Object obj, System.Int64 id) (at Assets/Plugins/Easy Save 3/Scripts/ES3ReferenceMgrBase.cs:151)
ES3Types.ES3ComponentType.ReadUnityObject[T] (ES3Reader reader) (at Assets/Plugins/Easy Save 3/Scripts/Types/ES3ComponentType.cs:71)
Any idea what is causing this? Is there a way to identify the asset that is being referred to by an invalid guid? Should there be a check when adding references to the dictionary that prevents adding invalid guids?

Any help is appreciated thanks!

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

Re: ArgumentException when deleting a component in a prefab

Post by Joel »

Hi there,

I've not seen this issue before, and I don't recognise the format you've pasted the data in. The guids you've pasted seem to be Unity GUIDs rather than Easy Save's reference manager's IDs. Would you be able to provide more information on where the data is from?

All the best,
Joel
Joel @ Moodkie Interactive
Twitter - Unity

FredTuna
Posts: 20
Joined: Sat Aug 10, 2019 3:16 pm

Re: ArgumentException when deleting a component in a prefab

Post by FredTuna »

This data is located in the .unity scene file under the ES3ReferenceMgr properties:

Code: Select all

MonoBehaviour:
  m_ObjectHideFlags: 0
  m_CorrespondingSourceObject: {fileID: 0}
  m_PrefabInstance: {fileID: 0}
  m_PrefabAsset: {fileID: 0}
  m_GameObject: {fileID: 586162896}
  m_Enabled: 1
  m_EditorHideFlags: 0
  m_Script: {fileID: 11500000, guid: 9a83408fcc9044c4fbc7e5d09a369ab6, type: 3}
  m_Name: 
  m_EditorClassIdentifier: 
  openReferences: 0
  openPrefabs: 0
  idRef:
    _Keys: (long list of keys)
    _Values:
...
    - {fileID: 2, guid: 00000000000000000000000000000000, type: 0}
    - {fileID: 2, guid: 00000000000000000000000000000000, type: 0}
    - {fileID: 2, guid: 00000000000000000000000000000000, type: 0}
...

There are about 100,000 values in that list with only a few having guids set to 0
Last edited by FredTuna on Mon Sep 23, 2019 6:22 pm, edited 1 time in total.

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

Re: ArgumentException when deleting a component in a prefab

Post by Joel »

Ah I understand what you mean now. Would it be possible to send me a basic project which replicates this so I can look into it at my end?

Null values should be cleared, so I'm not sure why this isn't happening.

All the best,
Joel
Joel @ Moodkie Interactive
Twitter - Unity

FredTuna
Posts: 20
Joined: Sat Aug 10, 2019 3:16 pm

Re: ArgumentException when deleting a component in a prefab

Post by FredTuna »

sO I tried to debug this by adding some code in the ES3SerializableDictionary.OnAfterDeserialize which accidentally broke things and cleared all the references in the ReferenceManager. Refreshing References did not add any reference with null guids. I could try adding a button to force clear all references to see if that fixes the problem every time.

I feel like this is caused by some code changes I have made which left some references to unity objects that no longer exist. For that reason, I don't know if I can replicate that in a smaller project.

FredTuna
Posts: 20
Joined: Sat Aug 10, 2019 3:16 pm

Re: ArgumentException when deleting a component in a prefab

Post by FredTuna »

Clearing and refreshing dependencies on the ES3ReferenceManager or individual ES3Prefab components doesn't seem to work. I managed to debug and find out which objects were being referenced with guids of 0 and they are all SpriteAtlas objects. From weat I understand if there are objects referenced with guids of 0, the lin
e in the asset won't be showing a guid like this:

Code: Select all

    - {fileID: 33480259190248396}
In the case of 3 separate SpriteAtlas (of type Texture2D), they are added with a guid of 0 like this:

Code: Select all

  - {fileID: 2, guid: 00000000000000000000000000000000, type: 0}
and I'm not sure why. Through all this at some point the issue fixed itself (and tons of prefabs containing an ES3Preab component were dirtied with apparently useless changes (just reshuffled lines) even though I didn't edit them).
Now I had to undo changes to two prefabs that wouldn't merge with a coworker's change and I don't know how to fix it once more.

Post Reply