x


custom inspector and edit mode script

Hey guys,

I have created a new inspector which I want to use in combination with a script which is executed during edit mode (using [ExecuteInEditMode]).

The custom inspector is written like this:

float rotation = 0.0f;

public override void OnInspectorGUI()
{
	rotation = EditorGUILayout.FloatField("Rotation:", rotation);
    
    // do something useful
}

This works very well as long as I keep the gameobject selected. As soon as the gameobject looses focus and gets refocused, the rotation is set to 0, the initial value, again. Did I do something wrong, or is it just not possible?

more ▼

asked Aug 03 '12 at 01:56 AM

DrahtMaul gravatar image

DrahtMaul
37 1 3 5

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Hi DrahtMaul,

This is because the rotation variable has to be declared on the script derived from Monobehavior and not from the editor script it self. All variables declared in the editor script are "reset" when you deselect the gameobject that has the script derived from Monobehavior.

I would recommend to read the following articles that explain it in more detail:

http://docs.unity3d.com/Documentation/Components/gui-ExtendingEditor.html

http://active.tutsplus.com/tutorials/workflow/how-to-add-your-own-tools-to-unitys-editor/

more ▼

answered Aug 03 '12 at 07:33 PM

rhodnius gravatar image

rhodnius
101 2

Yeah, I figured that out myself already, I just forgot to say that here. I'm sorry about that. Thank you for the links anyways!

Aug 03 '12 at 09:43 PM DrahtMaul
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3327
x466
x10

asked: Aug 03 '12 at 01:56 AM

Seen: 429 times

Last Updated: Aug 03 '12 at 09:43 PM