Hi my build of Android is including music files in the build which is causing my build size to increase. But I want ot load my music files from addressables so that my build size can be reduced. How can I do this?
It shows that music files are used by SettingsManager.asset which is used by References.asset so they were included in build.
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
You can define Music tracks (with labels) in the Editor, but leave the actual "Clip" asset field blank - and populate it at runtime via a custom script.
As with any Manager/Editor field, you can get an API reference to it by right-clicking the field's label, i.e.:
A typical script, with public functions to preload and assign clips, would look something like this:
I get these warning and errors. I created a script named "MusicAddressables" and assigned it to a game object. Then I assigned the addressable audio files in the fields. Left the Music Storage fields empty.
Screenshot of my setup. https://imgur.com/a/pfaYYgo
Cannot play _Music - no AudioClip assigned to track 11!
I've updated the above - it should remove the error now.
You will still need to load your music addressable at the intended time, however. If you make the GameObject the script is attached to a prefab, you can use the Object: Call event Action to reference that prefab and call its Assign / AssignAll functions as needed.
Should I add the action Object: Call event for every scene or just the first one?
Thank you Chris, it works perfectly in the editor. Checking on Android and will let you know about how it is.
Once a track has been assigned, it won't need to be again for the duration of that build.
With some slight tweaking, I've gone and made this a page on the AC wiki:
https://adventure-creator.fandom.com/wiki/Music_track_addressables
Thanks Chris, you are awesome.