Is there an easy way (script?) to replace assets within an event? I’ll have to create many variants of a complex event where I’ll duplicate the event to create a variant and then replace the underlying assets within the event. Let’s say I have Fiat_engine_low.wav used in multiple tracks in the event on a parameter sheet and Fiat_engine_low.wav as well and I want to replace them all with Harley_engine_low.wav and Harley_engine_high.wav without changing each assets fades, position or other settings. Any pointers? Could a script work here (I can’t write scripts unfortunately) Thanks!
Hi,
Sorry for the late response.
Yes, If you actually want every use of Fiat_engine_low.wav in the project to become Harley_engine_low.wav:
- In the Assets browser, find
Fiat_engine_low.wav. - Right click → Replace with…
- Choose
Harley_engine_low.wav. - Repeat for the “high” file.
Hope this helps!
Thanks, but unfortunately I want to keep using the assets in the original “source event” and only quickly replace the assets to use in the new copy. And I’d rather not do that manually for multiple loops for many vehicles…
Sorry if you know of this, and it is still quite a manual method, but you can select a single instrument and then drag a new file from the asset browser on top of the waveform at the bottom of the screen to replace the audio in an instrument. Of course, you’ll need to do this for every instance of the instrument, but at least the instrument fades and position will be retained.
Apart from manually replacing the assets inside the event, the only other option is to write a custom Studio script to automate the process.
Below is an example I made that can demonstrates how you can replace all instances of a specific audio asset inside the currently selected event with another one. This should give you a starting point to build a more complete workflow:
studio.menu.addMenuItem({
name: "Tools\\ Swap Assets In Event",
execute: function () {
function swapAssets(widget) {
// Get the current selected event
var evt = studio.window.browserCurrent();
if (!evt || !evt.isOfExactType("Event")) {
console.log("SwapAssets: No event selected.");
return;
}
// Retrieve asset paths from UI
var oldEdit = widget.findWidget("m_OldAssetText");
var newEdit = widget.findWidget("m_NewAssetText");
if (!oldEdit || !newEdit) {
console.log("SwapAssets: widgets not found.");
return;
}
var oldName = oldEdit.text();
var newName = newEdit.text();
if (!oldName || !newName) {
console.log("SwapAssets: empty old/new name, abort.");
return;
}
// Look up the new AudioFile asset
var newAsset = studio.project.workspace.masterAssetFolder.getAsset(newName);
if (!newAsset) {
console.log("SwapAssets: new asset not found: " + newName);
return;
}
var modules = evt.timeline.modules;
if (!modules) {
console.log("SwapAssets: no modules on event timeline.");
return;
}
var replaced = 0;
// Replace all SingleSound modules referencing the old asset
for (var i = 0; i < modules.length; i++) {
var inst = modules[i];
if (!inst.isOfExactType("SingleSound"))
continue;
var file = inst.audioFile;
if (!file)
continue;
if (file.assetPath === oldName || file.name === oldName) {
inst.relationships.audioFile.remove(file);
inst.relationships.audioFile.add(newAsset);
replaced++;
}
}
console.log("SwapAssets: " + evt.name +
" " + oldName + " -> " + newName +
" replaced " + replaced + " instance(s).");
}
// UI
studio.ui.showModalDialog({
windowTitle: "Swap Assets In Event",
windowWidth: 220,
windowHeight: 150,
widgetType: studio.ui.widgetType.Layout,
layout: studio.ui.layoutType.VBoxLayout,
items: [
{ widgetType: studio.ui.widgetType.Label,
widgetId: "m_OldAssetLabel",
text: "Find asset (Asset path):" },
{ widgetType: studio.ui.widgetType.LineEdit,
widgetId: "m_OldAssetText",
text: "" },
{ widgetType: studio.ui.widgetType.Label,
widgetId: "m_NewAssetLabel",
text: "Replace with (Asset path):" },
{ widgetType: studio.ui.widgetType.LineEdit,
widgetId: "m_NewAssetText",
text: "" },
{
widgetType: studio.ui.widgetType.PushButton,
text: "Apply",
onClicked: function () {
swapAssets(this);
this.closeDialog();
}
}
]
});
}
});
To use this script:
- Duplicate the original event to create a working variant.
- Select the duplicated event in the Event Browser.
- Run the script from the Scripts → Tools menu.
- Enter the asset path of the sound you want to replace and the asset path of the new sound.
Please note that this script works on the current selected event and was only tested with single events and a simple timeline setup.
If your events contain nested tracks or if you need to automate multiple events, you will need to extend the script accordingly.
Hope this helps!
