Hi all,
I think I need to submit this as a bug but I’m not entirely sure if this is not intended behaviour. I’m under the impression that private variables are not serialised by Unity unless you explicitly tell it to with [SerializeField]. But I was writing some editor scripts and discovered evidence to the contrary, code snippet below which shows this:
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class NewBehaviourScript : MonoBehaviour
{
private bool abool;
private int anint;
private string astring;
public void Update()
{
Debug.Log( "Update" );
Debug.Log( this.abool );
Debug.Log( this.anint );
Debug.Log( this.astring );
this.abool = true;
this.anint = 423;
this.astring = "hello";
}
}
If you attach this class to a GameObject in a scene, you’ll see in the console that “Update” is called, and all the values are at their defaults as they should be (false, 0, and blank). Then on the next call, they are true, 423, and “hello” as expected.
Now - clear your console, and then edit a script (like insert a space or something), save, and come back to unity and wait for it to compile. Once compilation has completed, it reloads the assemblies and Update is called again - but it keeps the values true, 423, and “hello”. So clearly it is serialising these private variables, but why?