I have a prefab with a string call CAKE initialized to APPLE in one of its component. I copy an instance of the prefab as one GameObject in the Hierarchy window. Then I use an editor script to modify the value to BANANA before the game is started.
In the inspector window, the value is correctly updated but not in bold.
When I start the game, it returns old value Apple.
If I modify the value manually in the inspector window, and start the game, it returns good value BANANA.
How can I update correcty the value using EDITOR SCRIPT ?
//PREFAB
public class DecorController : MonoBehaviour
{
public string CAKE = "APPLE";
}
//EDITOR SCRIPT
[CustomEditor(typeof(DecorController))]
public class DecorControllerEditor : Editor
{
SerializedProperty m_CAKE;
void OnEnable()
{
m_CAKE = serializedObject.FindProperty("CAKE");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(m_CAKE);
serializedObject.ApplyModifiedProperties();
}
void OnSceneGUI()
{
DecorController myController = (DecorController)target;
myController.CAKE = "BANANA";
}
}