Custom editor array without serialized object

Hi

I have an array of audio clips that needs to be assigned in the editor and the script is using a custom editor script. But I can’t find a way to make that array of audio clips work. I tried this but it didn’t work.

script.audioClips.walkFootstepSounds = EditorGUILayout.ObjectField(script.audioClips.walkFootstepSounds, typeof(AudioClip[]), true);

I have been Googling for a while and all I can find is to use seralizedObject but I can’t use it in the way my game is set up. Is there any other way I can make an array of audio clips without using serializedObject?

Thanks

I think you can use EditorGUILayout.PropertyField(serializedObject.FindProperty(“YourArrayName”),y), if that field is marked as [System.serializable]

You only have two options, either:

  • use EditorGUILayout.PropertyField like ValooFX said
  • Implement the array mechanics yourself using multiple editor controls.

For the first solution you just have to use something like:

EditorGUILayout.PropertyField(serializedObject.FindProperty("walkFootstepSounds"), true);

You don’t need to pass any return values since the scriptable object handles that itself internally when ApplyModifiedProperties is called.

For the second solution you have to handle everything yourself:

  • Display a foldout for the array and only display the following when it’s expanded.
  • Display an IntField for the item count of the array. When the count is changed you have to recreate the array and copy over the old elements.
  • Display an ObjectField for each element in a loop.