Have gameobjects with a script attached. They have enum drop downs. Randomly these enum values will reset to the default value. Not sure if this is from updating unity or something else. It has happened to me multiple times randomly. Nothing is affecting these values or changing them through code. Anyone else run into this issue?
No.
There are many ways to make this go wrong. An editor script that isn’t using SerializedProperty to apply the change, a Prefab that has Overrides or variants or gets reset from the scene. An Importer script that’s misbehaving, a reference in the prefab to an object outside the prefab hierarchy. A broken PropertyDrawer. Just to name a few.
Enums are bad in Unity3D if you intend them to be serialized:
It is much better to use ScriptableObjects for many enumerative uses. You can even define additional associated data with each one of them, and drag them into other parts of your game (scenes, prefabs, other ScriptableObjects) however you like. References remain rock solid even if you rename them, reorder them, reorganize them, etc. They are always connected via the meta file GUID.
Collections / groups of ScriptableObjects can also be loaded en-masse with calls such as Resources.LoadAll<T>().
Best of all, Unity already gives you a built-in filterable picker when you click on the little target dot to the right side of a field of any given type… bonus!
Change your IDE color when you’re into play mode, they probably reset itself because you’re doing changes during play testing. When you change the color of the IDE you will know that everything will be erased when you drop from play mode that way you can Copy the component before you exit play mode and then Paste it as you like the settings.
Happened so many times to me…
My work around will be just using int values and set correct enum on Awake()
Just found out that Serialized fields might reset by default with the values stated in the code editor.
They don’t. Once the values have been serialised, changing the initialised value does not affect any existing values.
Unless you accidentally change the spelling of the field without adding the [UnityEngine.Serialization.FormerlySerializedAs(“oldname”)] attribute, in which case yeah, it’s a whole new field to serialize…
As for enums, I have seen so much production code on MANY platforms like this:
public enum SomeImportantEnum
{
// NEVER RENUMBER THESE!!! ! ! !!!"1
_obsolete=1,
CommonlyUsedValue=2,
_also_obsolete=3,
TypicallyUsedValue=4,
_mark_told_me_to_delete_these=5, // 6, 7, 8
OftenUsedValue=9,
// see BUG352 for why we cannot use 10
FinalValue=11,
UserRequestedValue=12,
}
Not sure if half of these commenters know what you’re talking about.
This problem started for me in Unity 2022.3.18f, my first version after leaving 2021LTS.
On changes to the parent hierarchy, parent and child enum values reset to 0… Sometimes. It is not consistently reproduceable, but I’ve seen it triggered after changes to the prefab and changes to non-prefab objects in the scene.
All of my enum strings are explicitly assigned their int values in code (eg. “None = 0”). Still, after assigning an enum value from the inspector dropdown, the value (and inspector) reset to 0 on a whim.
Anyways, you’re not crazy, and I did not experience this problem for years before moving to 2022. If I find anything more to add I’ll come back here to share.
Edit 1: I’m seeing this on new 2022 projects as well as projects that have been upgraded from 2021.
Edit 2: I should also clarify that not all enums get reset. For example, just now I had 2/3 reset after making changes to a prefab hierarchy.
I found out in my current project that multi-selecting ScriptableObject-assets resets the first enum-field to default value. Rest stay in the state they were in. Coworker reported similiar stuff to the reply above this. Seems like a Editor bug for sure.
Hi,
We have some fixes for this in review at the moment, this is the issue tracker link Unity Issue Tracker - Enum flag field resets to the first value in the Inspector when selecting multiple objects with different Enum flag field values
Pretty sure the issue I posted just before your comment is the same identical issue and that one is already marked as fixed lol
https://issuetracker.unity3d.com/issues/serializefield-enum-resets-to-the-first-value-in-the-inspector-when-selecting-multiple-objects-with-different-enum-values
The one you posted had some further issues that are being addressed in the one I posted ![]()
Ah nice fair enough
Awesome!!
We are looking forward to this fix too, it is very dangerous as you can lose values just by selecting objects!
This bug is still present in 2023.2.20f1
- Unity Issue Tracker - SerializeField enum resets to the first value in the Inspector when selecting multiple objects with different enum values
- Unity Issue Tracker - Enum flag field resets to the first value in the Inspector when selecting multiple objects with different Enum flag field values
@karl_jones should I create a new issue for this or is it already planned to fix it in the next releases of 2023?
2023.2.20f1 does not have both fixes. You will need to upgrade to Unity 6 as backports for 2023.2 are now closed.
If the issue is still on the latest Unity 6 then please file a new bug report.
Regarding the first issue tracker link, in 2022 the issue isn’t fixed in the versions passed the one mentioned in the issue tracker as the “fixed version”.
fixed version: 2022.3.16f1
bug visible in: 2022.3.25f1
proof:

The 2nd issue tracker however mentions it’s fixed in 27f1. I’ll install a later version and try it, but the 1st bug report was not fixed while closed as fixed.
Just tested this in the latest 2022.3 (2022.3.57f1) version and couldn’t recreate this behaviour. Ideally testing isn’t done with a version 32 revisions out of date.
That said: Oof. All those enums that should be scriptable objects instead.