Scripting API: Checking if an audioFile object is valid

Hello,

I’m writing some automation with JavaScript using the Scripting API. One of the things I’m doing is iterating through all events in my FMOD project and getting a list of all audio assets referenced by an event, however I’m running into an error when getting an asset from an event that has an instrument with no assets assigned.

Code snippet:

for( var j = 0; j < instruments.length; j++ )

{

     if( instruments[ j ].entity === "SingleSound" )

     {

     sourceFileList.push( instruments [ j ].audioFile.assetPath );
     }

}

How can I check if the audioFile or the audioFile.assetPathare valid? Adding an if statement to check if audioFile != null (nor checking if audioFile.assetPath != null) have not worked so far.

Best,

Caio

Hi,

I unfortunately haven’t been able to reproduce the behavior you’re describing. Standard != null checks on audioFile and then audioFile.AssetPath work as expected on my end. Could I get your exact FMOD Studio version, as well as a complete script that reproduces the issue you’re describing? Also, what is the specific error that you’re receiving from Studio when this happens?

As an aside, if they exist/aren’t null, all ManagedObjects also have an isValid boolean property you can check to ensure the object’s properties are internally consistent.

I just realized I was checking for [null]instead of just null for some reason (don’t ask me why lol) so now it works. Good to know about isValid tho, thanks!

1 Like

Happy to hear that you resolved the issue!