Trouble getting multi edit working in an editor script.

Hi all,
Just trying to get Multi editing working in an editor script and I’m finding it pretty confusing.
So I’m using the [CanEditMultipleObjects] at the top of the editor script, then this -

    SerializedProperty aSerializedCheckBox;   
    void OnEnable()
    {
        // Setup the SerializedProperties.
        aSerializedCheckBox = serializedObject.FindProperty ("aCheckBox");// Find with a string? Really?
    }
   
    public override void OnInspectorGUI()
    {
        serializedObject.Update ();
       
        var targetComponent = (Element2) target;
        EditorGUILayout.ToggleLeft("test", aSerializedCheckBox);

I have a property called “aCheckBox” on the target script but I’m getting an error with this saying -
Argument 2: cannot convert from ‘UnityEditor.SerializedProperty’ to ‘bool’

Any idea what I’m doing wrong here?
Thanks,
Pete

Line 14 should be EditorGUILayout.PropertyField(aSerializedCheckBox); or one of its overloads.

Also, ensure you call serializedObject.ApplyModifiedProperties() at the end of the OnInspectorGUI loop.

Ahh that’s awesome thanks @Munchy2007 !

Hey do you know how you’d do something like a button?
I thought I might be able to use targets and then just get the button to apply to all of the targets.
But if I use this
var targetComponents = (Element2[]) targets;
I get - InvalidCastException: Specified cast is not valid.

See the answer given by darkgaze (not the green ‘accepted’ post) in this Unity Answers thread, it shows a simple example of how to use the targets property.

Will do! Thanks for the help :slight_smile:

Just to clarify, you don’t cast the entire array to the correct type, you cast each element of the array as you iterate over it.

Yeah, just got it working :wink: thanks!