Enum Value Changing At Runtime On A Prefab

Greetings Unity!

So I have an issue with an enum that I am setting via an editor window I’m working on.

Here’s the code I’m using to change it:

if (GUI.Button (new Rect (windowWidth / 2 + 120 + (buffer * 5), 265, 32, 32), offFade, editorSkin.GetStyle ("Button"))) 
					collectionToShow.fadeMode = AudioManager.fadeStyle.Off;

Viewing the public enum state, it does appear to change to fadeStyle.Off.

However, when I click the play button, it jumps to a different one.

The first thing I thought was “Oh, I must have a Start() or Awake() function that is setting it somehow.” But nope. The reason I know this isn’t the case is that when I manually set the enum value (by clicking the drop-down menu and clicking on it myself instead of setting it with the editor window button) it doesn’t change when I click play.

Similarly, this happens when I change a float too! What’s going on here? Why don’t my other scripts take my editor script seriously? I’ve tried setting the scene dirty and saving it, but no luck.

Thanks!

Found an answer to this within this thread.

I’m not sure if this only happens with prefabs, or if it happens on regular GameObjects - but I’m assuming prefabs.

Apparently setting values within an editor window is seen as setting them at runtime (when it’s done on a prefab), and it discards the changes internally immediately after changing the value. However, it still serializes the proper value on the public enum/float fields.

The way to handle this is to use the prefab utility (see the link for more). You essentially just have to click the “Apply” button on a prefab via script.