- Home /
MonoBehavior Prefab modified by script in Editor loses changes when Play is hit
(OK, I know this sounds similar to the post I posted a few days ago, and it's the same problem. Original post had two questions, and one was solved and marked answered. Didn't want to lose out on this question getting answered.)
I've seen this question asked before and almost every time the answer is that the person is using a ScriptableObject. I am not. I have a MonoBehavior script that randomly resizes the prefab it is attached to. I have it set to [ExecuteInEditor] and it works flawlessly. But when I hit Play, the instance reverts to what it looked like as a prefab, before the script was run. When I hit stop, it goes back to it's new scaled version. Simply put:
In Editor: Scaled Correctly. In Game: Reverts to Prefab scale. Back to Editor: Back to Scaled Correctly
Any ideas why a prefab that's been scaled in editor mode via script would lose those scalings when run, but get them back when returned to the editor? SetDirty(gameObject) is called.
Answer by Tanoshimi2000 · Apr 27, 2015 at 10:18 PM
Found the problem. It turned out my custom animations contained keyframes for Scale, and this was overriding the editor scaling.