- Home /
SerializeField does not work when a value set using code
Hi.
I'm sure you have read the beautiful guide on when to use serialization to save the values from being reset when Play button is played.
The issue I have is that it doesn't work in this particular case and I would appreciate if anyone can pinpoint the obvious that I'm blinded to.
Here's a piece of my editor Menu item code:
Vector3 MinPointOnMap = new Vector3(direction*MinPointOnArea[0],0,MinPointOnArea[1]);
go.GetComponent<MapBoundaries>().MinPointOnMap=MinPointOnMap;
EditorUtility.SetDirty(go);
What I'm trying to serialize is the "go" object which is an instance of monobehaviour and is available in the scene:
using System;
using System.Collections;
using System.Linq;
using System.Xml;
using Aram.OSMParser;
using UnityEngine;
[Serializable()]
public class MapBoundaries : MonoBehaviour {
[SerializeField()]
public Vector3 MinPointOnMap;
void Start () {}
void Update () {}
}
After running the editor code, I can see that the values have been changed and set (Bold values): ![Bold means modified][1]
But when I hit the play button, they all go to zero!
Thanks,
Aram [1]: /storage/temp/15412-serialization.png
Your answer
![](https://koobas.hobune.stream/wayback/20220613114055im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Can a GameObject be serialized? 1 Answer
Editor Script not saving after first time playing 2 Answers
Is EditorUtility.SetDirty restricted to prefabs or inspected GameObject? 5 Answers
Editor windows disappear on play in Unity 5.5.2f1 1 Answer
Why does my Unity Serialization not work? Do i miss something? 1 Answer