Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by RealMTG · Sep 12, 2015 at 02:16 PM · editorarrayaudioclipcustom editor

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Polymo · Sep 12, 2015 at 02:19 PM

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

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RealMTG · Sep 12, 2015 at 02:42 PM 0
Share

I did this...

 script.audioClips.walkFootstepSounds = EditorGUILayout.PropertyField(serializedObject.FindProperty("walkFootstepSounds"));

and that did not work. "Cannon implicitly convert type 'bool' to 'UnityEngine.AudioClip[]'. But my array is also stored inside a class that is inside the target class if that helps any. That is why I don't want to use these serialized things.

avatar image Polymo RealMTG · Sep 12, 2015 at 04:04 PM 0
Share

you dont have to assign the result back to the variable. But what you should do ins$$anonymous$$d is Apply$$anonymous$$odifiedProperties() at the end of the OnGUI block. Edit: as Bunny83 below said.

avatar image RealMTG · Sep 13, 2015 at 06:55 PM 0
Share

After countless tries at workarounds I finally went with this. It somehow felt "dirty" but it works. Thanks.

Unity also needs to add a easier way of adding arrays...

avatar image
0

Answer by Bunny83 · Sep 12, 2015 at 03:19 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

28 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Custom Editor + Array = A Long Nightmare ! 1 Answer

Custom Editor for array of custom class 1 Answer

Undo.Record: Recording variables within array elements 0 Answers

Custom Editor loosing data on play 1 Answer

Slideable Float Field in Custom Editor 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges