Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Ruffer07 · Dec 22, 2017 at 05:31 PM · arrayaudioclipcustom editordrag-and-drop

Drag and Drop into Custom Inspector ObjectField not Working

Hello, I'm creating a custom inspector for my audio player/visualizer for an assignment at uni and have got this far. Now I'm having an issue with dragging and dropping an AudioClip into the clip into the Custom Inspector AudioClip objectfield.

I think it's something to do with it not updating the am.audioClips[count].clip in the for loop. I can drop the AudioClips into the default inspector below and it updates the custom inspector but not vice versa. You can select the object in the custom inspector but can't delete it by pressing delete on keyboard.

I'm sure it's fairly simple but any help would be greatly appreciated!


alt text


alt text


 using UnityEngine;
 using UnityEditor;
 
 // Reference to the script that this custom inspector script affects.
 [CustomEditor(typeof(AudioManager))]
 [CanEditMultipleObjects]
 public class CustomAudioTrackInspector : Editor
 {
     AudioManager am;
 
     // Launches when script is fired.
     void OnEnable()
     {
         am = (AudioManager)target;
     }
 
     public override void OnInspectorGUI()
     {
         // Label at top of the AudioManager.
         GUILayout.Label("This script handles the audio functions, i.e. Play, \nPause and Stop. Audio clips are also added here.");
         GUILayout.Label("Total Audio Clips: " + am.audioClips.Count);
         if (GUILayout.Button("Add AudioClip"))
             AddAudioClip();
      
         for(int count = 0; count < am.audioClips.Count; count++)
         {
             GUILayout.BeginHorizontal();
             if (GUILayout.Button("Remove AudioClip"))
                 RemAudioClip(count);
             //am.audioClips[count].clip = Selection.activeObject as Object;
             am.audioClips[count].name = GUILayout.TextField(am.audioClips[count].name, GUILayout.Width(100));
 
             // Displays correctly and accepts audioclips but still says none after dropping a clip in.
             EditorGUILayout.ObjectField(am.audioClips[count].clip, typeof(AudioClip), true); 
             
             GUILayout.EndHorizontal();
         }
 
         GUILayout.Space(20);
         base.OnInspectorGUI();
     }
     
     // In-Editor function to add an AudioClip to the audioClips list.
     void AddAudioClip()
     {
         am.audioClips.Add(new Audio());
     }
     // In-Editor function to remove an AudioClip from the audioClips list.
     void RemAudioClip(int index)
     {
         am.audioClips.RemoveAt(index);
     }
 }
 



If i put this instead am.audioClips[count].clip = EditorGUILayout.ObjectField(am.audioClips[count].clip, typeof(AudioClip), true); which seems logical i get an error saying it cant convert type 'UnityEngine.Object' to 'UnityEngine.Audioclip'.

capture2.png (34.4 kB)
capture.png (31.9 kB)
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

1 Reply

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

Answer by justDeek · Dec 22, 2017 at 09:54 PM

You have to cast the whole EditorGUILayout.ObjectField(); for it to specify as that object type.

In your case:

 am.audioClips[count].clip = (AudioClip)EditorGUILayout.ObjectField(am.audioClips[count].clip, typeof(AudioClip), true); 
Comment
Add comment · Show 1 · 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 Ruffer07 · Dec 23, 2017 at 03:30 PM 0
Share

Perfect, just what I was looking for! Useful knowledge for the future, thank you very much.

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

132 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 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 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 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 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

Please help! Audio not working in another class.. 0 Answers

play sound from an array 2 Answers

How to make drag-drop detecting Editor script? 0 Answers

IndexOutOfRangeException: IndexOutOfRangeException: Array index is out of range. FollowTarget.Update () (at Assets/Scripts/FollowTarget.cs:29) 1 Answer

Arrays - picking a random object 0 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