- Home /
Add AudioClip to Inspector Programmatically
Hi there,
I currently have a program that imports a spreadsheet to the editor and creates a new gameobject. Everything works great, except for the field that I want to reference an AudioClip.
Basically any strings get imported fine and I can see their values in the Inspector, but any strings that we try to use as a path for the AudioClip does not seem to work. The Inspector will not show or link to the AudioClip asset in any way.
To try to set the AudioClip we have something such as:
AudioClip myAudio = Resources.Load(currentItem.myFileToLoad, typeof(AudioClip)) as AudioClip;
//myFileToLoad is a string containing the asset name with no extension
Thanks in advance!
Answer by rutter · Mar 07, 2012 at 01:37 AM
If this is an editor script, you can use AssetDatabase.LoadAssetAtPath()
This worked perfectly - I had to add a new function into my editor script and processed the audio after I had the GameObject created by the first part of the script. Now I just need to loop through all the items where this needs to be set and I should be golden!
Thanks for the tip!
Your answer