Download

Editor UI block adding when default value is present

“Cannot add a new key to map while a key with default value exists” occurs when trying to add new items when default value is present.
This behavior makes sense for a lot of types (especially objects and structs).
An easy way to circumvent this warning is to set the entry that has the default value to something else, then add a new entry, modify the key, then restore the original back to the default.
However for enums this doesn’t work so well.
The last entry has to be planned ahead of time to be the default entry.
This is because if all the enumerations are added, then none of the keys can be changed as changing one would cause collision with another.
In situations where an enum is modified to have an additional entry after the map is made, then it is not as simple a task to add it.
Take the following example:
enum NUMS { 0,1,2}
map <NUMS,floats>
key: 2 value: 5.0f
key: 1 value: 6.0f
key: 0 value: 7.0f
*modify NUMS to be {0,1,2,3}
When clicking the add button a conflict will occur since 0 is in use.
*change 3rd entry key from 0 to 3
key: 2 value: 5.0f
key: 1 value: 6.0f
key: 3 value: 7.0f
*click add button
key: 2 value: 5.0f
key: 1 value: 6.0f
key: 3 value: 7.0f // we wanted NUM::0 to be 7.0f not NUM::3
key: 0 value: 0.1f
Notice that there is no way to modify any of the keys since modifying one would cause collision with another.
This means the values now need to be copied around.

This example is trivial, and it only takes a few more extra steps to deal with the issue manually.

Solution Proposal:
Instead of attempting to add the default key to the map, instead add the next available key to the map.
This would be nice for other types as well such as integers, floats, string, and others. Although the problem isn’t as bad with those types.

Obviously this is not a high priority issue, but it would be a nice quality of life change.