Dictionary lose it's value after refactor/rename the "field" name.

Issue #507 resolved
Lazy Knight created an issue


[SerializeField] private Dictionary<NpcType, GameObject> a;

rename to (by Rider refactor):
[SerializeField] private Dictionary<NpcType, GameObject> b;

after this, the values stored in the inspector were fully lost.

Which means if that we want to use the inspector as the database, we're in danger.

  • Odin Version: 2.0.15
  • Unity Version: 2018.3.6f1 Personal

Hope this could be fixed soon.

Comments (5)

  1. Lazy Knight reporter

    The "Rename" works well in other variable types, currently, Dictionary is the only type which will lose the values in inspector after rename.

  2. Nicolás Ezcurra

    I think this behaviour is normal. After renaming a serialized field, you should use the attribute FormerlySerializedAs in order to keep the existing serialization data which points to the former field name. In your case it should be:

    private Dictionary<NpcType, GameObject> a;
    private Dictionary<NpcType, GameObject> b;
  3. Tor Esa Vestergaard

    As Nicolas says, this is indeed expected behaviour, and not a bug. If you rename the field and provide no extra information such as a FormerlySerializedAs attribute, we have no way of knowing that the dictionary should now go into the 'b' field.

  4. Log in to comment