Object array and editor

Hi !

I am trying to create an Editor script for one of my class.

It is possible to drag and drop a GameObjects in the editor and the list of all components appear.

When you select a component, the list of all functions in the component appear.

When you select the function you want to call, the list of all parameters used by the function is displayed.

I stock all parameters as object in an object array.

My container class is Serializable and the object array is a “Serializable Field”.

But when I start the game, all my parameters in my object array are set to “NULL”… all the parameters are lost :frowning:

I need some advices over here ^^

Thanks

Are you using: “MyObject objects[ ]”, or some other kind of array?

I believe you have to use “EditorUtility.SetDirty(target)” to tell Unity to update the edited object’s … uh, stuff in the project. So it saves between edit and play mode. There’s a word for that stuff.

It is excalty an object[ ] I am using in my project.

I will try the SetDirty() method as soon as possible !

Thanks for your advice !

Edit :
It doesn’t work. (but I maybe dont insert it at the right place).
My object[ ] just contain one parameter which is a int set to 5;
When I press Play, my object[ ] contain one parameter : null

This here should work:

class Thing {
  @HideInInspector var ints : int[];
  @SerializeField private var floats : float[];
}
@CustomEditor( Thing )
class ThingEditor extends Editor {
  function OnInspectorGUI() {
    // allow editing of target.ints and target.floats
    if ( GUI.changed ) EditorUtility.SetDirty( target );
  }
}

If you havve this instead:

class ThingEditor {
  var objects : int[];
  etc...
}

You need to save to an external file or use EditorPrefs ; Editor classes don’t save their own variables between assemblies.

I got one class containing values and the parameters (object[ ]) :

[System.Serializable]
public class ItemCaller : MonoBehaviour 
{
    public GameObject gameobjectTocall;
    public Component scriptToCall;
    public int selectedMethod;
    public MethodInfo methodToCall;
    [SerializeField]
    public object[] parameters;

    void Start()
    {
        Debug.Log(gameobjectTocall);
        Debug.Log(scriptToCall);
        Debug.Log(selectedMethod);
        Debug.Log(parameters.Length);
        Debug.Log(parameters[0]);
        //methodToCall.Invoke(scriptToCall, parameters);
    }

}

And my EditorClass :

[CustomEditor(typeof(ItemCaller))]
public class EditorTest : Editor 
{
    private ItemCaller actual;

...

    public void OnEnable()
    {
        actual = (ItemCaller)target;
        ...
    }

    public override void OnInspectorGUI()
    {
        serializedObject.Update();
		
        if ( GUI.changed ) EditorUtility.SetDirty( actual );
        ...
    }
}

I put your line there, I think it is ok…

I put paramters value on my object array and they are keep in memory in the editor.

But when I play my scene, all parameters are OK onyl my object[ ] is full of null items.

Debug.Log(parameters[0]); => Null

I need somebody help !

Need somebody helppppppppppp =)