Assigning Audio to Events via Script?

I’m trying to automate creating events in bulk via script. I have all necessary assets imported and verified uncorrupted files, but for some reason I’m getting the following errors when trying to associate files (all .OGGs) with the created events’ tracks: “Relationship ‘audioFile’ expects a destination of entity type ‘AudioFile’”

Is there a way to cast resulting object from studio.project.workspace.masterAssetFolder.getAsset() to an AudioFile? If not, is there another function I should be using to access audio assets? The documentation is not clear on best practice/any approach here.

Relevant code snippet:

var asset =studio.project.workspace.masterAssetFolder.getAsset("/VOX/"+rowData[1]+".ogg");
	if(asset!=null){	
		//This results in missed files, but allows execution to continue. if(asset.isOfExactType('AudioFile')){ 
			console.log("Found asset: "+rowData[1]+".ogg, "+typeof asset);//asset type output as 'object' regardless of if an AudioFile or not	
			var track = event.addGroupTrack();
			var sound = track.addSound(event.timeline, "SingleSound", 0, 10);
			sound.relationships.audioFile.add(asset);
			sound.length = asset.length;
		//}
1 Like

Hi,

Your code works without issue on my end when testing with both FMOD Studio 2.02.00 and 2.02.17. What version of FMOD Studio are you using? Additionally, can you provide me with a dump of asset when it causes the issue you’re observing? You can do so with asset.dump().

Also, if you wish to retrieve the type of a given object in Studio, instead of using typeof, you can use the .entity property - i.e. asset.entity.