FlaShG/GitMerge-for-Unity

MergeManager.BuildAllMergeActions() Fails On Duplicate GameObjects

randomPoison opened this issue · 3 comments

When merging my scene I get a crash in MergeManager.BuildAllMergeActions() in the following loop (starting at line 72):

        foreach(var theirs in theirObjects)
        {
            theirObjectsDict.Add(ObjectIDFinder.GetIdentifierFor(theirs), theirs);
        }

When trying to add the new object to theirObjectsDict, if the object identifier key has already been added to the dict it throws an exception and the merge doesn't start. Checking if the object is already in the dict before adding it fixes the problem, though the more robust fix would be to see why there are duplicate objects in the first place. I tried tracking down where the duplicate comes from, but I couldn't see anything that would be causing the duplicate.

I guess you are using Unity 5?
The key is the ID grabbed from the m_LocalIdentfierInFile property of the object. You can inspect it by setting your inspector to "Debug". Unity 5 seems to have introduced that this property is 0 instead of something unique for objects that do not differ from their respective prefab counterpart.
See #17 and http://forum.unity3d.com/threads/how-to-get-the-local-identifier-in-file-for-scene-objects.265686/#post-1958081

I'm using unity 4.6. This doesn't happen for everything, it's only happening for one object in my scene.

When you're getting the unique id for the game object is there a reason you can't use GetInstanceID()? That seems like what you want. Nevermind, I read the post you linked and I think I understand why.

Yup. Just in case (or for people reading this later): GetInstanceID returns the ID of the object currently created. This ID expires after a session. (Re)loading a scene causes those IDs to be re-generated.

On Topic: It is possible that 4.6 is also handling the m_LocalIdentfierInFile property for Prefabs in a way that I didn't recognize yet. I'll look into it.