This is my first time trying to create an Editor script to edit an prefab properties and values through the Editor. I am having issues saving the prefabs array. I am able to add/remove objects to the array, but once I click on the PLAY button, the array is destroyed.
This is my Editor script:
`
#pragma strict
@CustomEditor(MyController)
class MyControllerEditor extends Editor
{
function OnInspectorGUI()
{
var my : MyController = target as MyController;
GUILayout.BeginHorizontal("Button");
if ( GUILayout.Button("Add Object to Array") )
{
my.someArray.Push(new Object());
}
if ( GUILayout.Button("Remove Object from Array") )
{
my.someArray.RemoveAt(0);
}
if ( GUILayout.Button("Remove All from Array") )
{
my.someArray = new Array();
}
GUILayout.EndHorizontal();
my.randomVariable = EditorGUILayout.IntField("Hello", my.randomVariable);
}
}
`
This script is attached to the prefab:
`
#pragma strict
var someArray : Array = new Array();
var randomVariable : Int = 0;
class someObject()
{
var prop1 : String = “a value”;
var prop10 : String = “a longer value”;
}
`
Am I doing this the proper way? How come the array is being destroyed when I PLAY and STOP the game in the Preview? Side note: setting the ‘randomVariable’ in the Editor works fine.
I have looked at that and have tried this but it doesn't work:
– gregmax17EdtiorUtility.SetDirty(target);Am I using incorrectly?SetDirty just tags that an asset needs saving. It is not used for non-prefab changes like this.
– Waz