Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Custom editor, how to retrieve an AudioClip?

Discussion in 'Scripting' started by Lucgnl, Mar 25, 2023.

  1. Lucgnl

    Lucgnl

    Joined:
    Apr 13, 2020
    Posts:
    2
    Hi,
    I'm making a custom editor for one of my MonoBehaviors and i'm trying to access a serialized AudioClip from the custom editor.
    The AudioClip:
    [SerializeField] AudioClip audioClip;

    What I have tried:
    Code (CSharp):
    1. public AudioClip clip;
    2.  
    3. void OnEnable()
    4. {
    5.     clip = Selection.activeObject as AudioClip;
    6. }
    The issue with this is that the AudioClip always returns as null.
    Any help would be appreciated as I'm relatively new to custom editors in unity.
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    6,015
    Lucgnl likes this.
  3. Lucgnl

    Lucgnl

    Joined:
    Apr 13, 2020
    Posts:
    2
    Thanks a lot that solved everything!