- Home /
Editor Script not saving after first time playing
This is a very weird behavior. I have a very complex editor script and it seems like it will only save the first time I use it before I hit the play button. Here is my step by step.
Create GameObject
Attach A Script
Open Editor Window
Adjust setting in Editor Window
Hit Play (everything is still there)
Hit Play (to stop)
Adjust setting
Hit Play...the changes revert to Adjustment in step 4
Go edit any script in my project
Adjust settings in Editor Window
Hit Play...everything saves again but only this time
I am using EditorUtility.SetDirty to save the info to my script attached to my GameObject. And I have Serialized every field and class, probably more than it needs. I will try to get a simplified example upload later.
[EDIT] I am adding an example package that is simplified version of what I am experiencing. You can open the window when in Unity going Window > Test Editor
Answer by Adamcbrz · May 07, 2012 at 03:16 PM
I found a solution to my problem. It appears that I am loosing my reference to the MonoBehavior when I hit play. What i am doing is probably overkil but I am re finding the script OnEnable, OnSelectionChange, OnFocus, and OnHierarchyChange. That caused it all to work perfectly. I am sure this is not the optimal method of doing this but it works for now.
Can you be more specific with that solution ? What do you mean by "re finding" ? Thanks.
Answer by fafase · May 07, 2012 at 01:32 PM
When variables are public they are shown in the Inspector.
The values given to the variables in the script will be used only the first time. After, you need to change them from the Inspector. Chnaging them in the script editor won't alter them in the script. Only the constants will be changed from editor script.
Ok sounds good. Is there anything I can do to solve this issue. What do you mean by "constants"?
Constant is like numbers. If you have
position.x += 10;
and
var speed:int =10; position.y += speed;
speed is a variable, if declared as public you will alter it from the inspector. If you get back to the editor and give it value 100, it won't change for all the objects you have already assigned the script. If you assign it to an object after alteration, then this object has the new value.
10 is a constant number, you cannot modify its value. But if you change 10 for 100 then it moves 10x faster.
Your answer
Follow this Question
Related Questions
List Contains false after playmode 0 Answers
A node in a childnode? 1 Answer
SerializeField does not work when a value set using code 0 Answers
How do i go about generating stuff in editor and keeping it in play mode 2 Answers
adding items to my list 1 Answer