Trouble updating editor with custom inspector.

I have this script that creates an “update scene” button inside the inspector
the problem is that the update button is not working properly.
I need to press the update button and then select the toggle,
while logic would sugest the other way around.
It works fine in the testtarget.js script, select the settings,
hit the showpreview toggle and it updates.
But I created this editor script to hide away the clutter of reference objects and materials so its easyer to use for artists.

Examples below are dumbed down version of the scripts as I also change materials.

editorscript help.js:

    @CustomEditor (testtarget)
class help extends Editor
{
	private var showHelp 		: boolean = false;
	private var lightOn			: boolean = target.lightIsOn;
	private var dynamiclight 	: boolean = target.useDynamicLight;

    function OnInspectorGUI () 
    {
		lightOn = EditorGUILayout.Toggle("Light Start On", lightOn);
		dynamiclight = EditorGUILayout.Toggle("Dynamic Light", dynamiclight);
		if(GUILayout.Button ("Update editor views")) 
		{
			UpdateScene();
		}
	}

	function UpdateScene()
	{
		target.lightIsOn 		= lightOn;
		target.useDynamicLight 	= dynamiclight;
		target.showPreview 		= true;
	}
}

And the scipt its changes the inspector for testtarget.js

var lightIsOn			: boolean 	= false;
var useDynamicLight		: boolean 	= false;
var dynamicLightsource	: Light;
var lampModel			: GameObject;

var showPreview			: boolean = false;

@script ExecuteInEditMode()


function Awake()
{
	if(lightIsOn)
	{
		LightOn();
	}
	else
	{
		LightOff();
	}
}


#if UNITY_EDITOR
function Update()
{
	if (showPreview)
	{
		if(lightIsOn)
		{
			LightOn();
		}
		else
		{
			LightOff();
		}
	}
	showPreview = false;
}
#endif


function LightOn()
{
	dynamicLightsource.enabled = true;
}



function LightOff()
{
	dynamicLightsource.enabled = false;
}

ugh having the biggest trouble to make the code readable, the code tags seem broken
ctlr+k seems to work, and the editing field could have been a bit bigger too :slight_smile:

For anyone with a simular problem stumbling on this thread this does the trick in above scripts:

	if (GUI.changed)
	{
    EditorUtility.SetDirty (target);
    target.showPreview = true;
}

Made the scripts a bit simpler as well:
Editor script:

@CustomEditor (testtarget)
class help extends Editor
{
	private var lightOn			: boolean = target.lightIsOn;
	private var dynamiclight 	: boolean = target.useDynamicLight;

    function OnInspectorGUI () 
    {
		lightOn = EditorGUILayout.Toggle("Light Start On", lightOn);
		dynamiclight = EditorGUILayout.Toggle("Dynamic Light", dynamiclight);
		
		if (GUI.changed)
		{
            EditorUtility.SetDirty (target);
            target.Awake();
        }

	}

}

And the target script:

var lightIsOn			: boolean 	= false;
var useDynamicLight		: boolean 	= false;
var dynamicLightsource	: Light;
var lampModel			: GameObject;


@script ExecuteInEditMode()


function Awake()
{
	if(lightIsOn)
	{
		LightOn();
	}
	else
	{
		LightOff();
	}
}



function LightOn()
{
	dynamicLightsource.enabled = true;
}



function LightOff()
{
	dynamicLightsource.enabled = false;
}