- Home /
Question by
Bluestrike · Nov 25, 2014 at 08:54 AM ·
editor-scriptingpolymorphism
Edit a inspector variable from editor script.(its not saving)
I need to give my objects of a same parent class a different ID. I wrote a editor script to do this and that works.
But when I save and load the scene, the ID have their default values again.
The parent class that hold the ID:
public class SavableClass extends MonoBehaviour
{
public var uniqueSaveID : int;
}
The editor script:
public class SaveIDsManager extends ScriptableWizard
{
new function OnGUI() :void
{
if(GUILayout.Button("Set Save ID's"))
{
SetIDs();
}
}
function SetIDs() :void
{
var SavableClasses : SavableClass[] = FindObjectsOfType ( SavableClass );
for ( var saveScript : SavableClass in SavableClasses )
{
// If no ID
if ( !saveScript.uniqueSaveID )
{
saveScript.uniqueSaveID = FindFreeID();
}
}
function SetIDs() :int
{
// code checking what id is next
var availebleID : int = 10;
return availebleID;
}
}
}
Comment
Best Answer
Answer by Bluestrike · Nov 25, 2014 at 09:04 AM
Found it, I must mark the edited script as 'dirty' by adding this code on line 21 in my editor script posted in the main post:
EditorUtility.SetDirty ( saveScript );