variable becoming null at runtime

So I am currently using a class that is executing in edit mode to set the variable of an instantiated class on an object that is not executing in edit mode.

What appears to be happening is when i run the program the object script is re-initializing the variable to null. (I have no code in the start or awake function telling it to do that, the variable is declared in the class as public Tile tile).

I thought that changing the class to also execute in edit mode might change it but it did not. What am i doing wrong here?

Why is the Tile variable being set to null at runtime ? Thanks in advance.

My guest is that your script in edit mode does not make changes permanent. Serialization problem…

To test if I’m right, add a var (like int test = 5;) in the instanced class and have your edit mode script modify it to another value.

Pressing play should return the value to 5.

To solve that, you could do an editor class that will handle modification to your instances class, that’s exactly what they are for!

Here is an example that will modify the mPoint member of a Path object to Vector5 (5,5,5), when you select it in the editor.

I think you can go from that and build whatever you want, good luck!

[CustomEditor(typeof(Path))]
public class PathEditor : Editor
{
   private SerializedObject mPathSer;
   private SerializedProperty mPoint;
   private Path mPathObj;

   void OnEnable()
   {
	   mPathObj = target as Path;
	   mPathSer = new SerializedObject(target);
	   mPoint = mPathSer.FindProperty("mPathPoint");
   }

   public override void OnInspectorGUI()
   {
	   base.OnInspectorGUI();
       mPoint.vector3Value = new Vector3(5,5,5);
	   mPathSer.ApplyModifiedProperties();
   }
}