Hello, I would like to know how do you approach sound in your UI.
Game interface without sfx is kind of useles and I can’t see any elegant way to attach sounds to buttons, sliders or custom elements, so I would like to know what is good way to tackle this problem.
By “elegant” I mean something built-in into buttons, for example in old UI I would create one prefab of button with all visual and audio functionality, then all instances would work in the same way.
Acceptable option would be if there was possibility to assign AudioClip in uxml builder, or even better - scriptable object and use it as audio provider/reference. I really want to avoid finding all buttons separately for every single template…
Sure, but it does not solve my problem in any way. The card is under consideration, so assuming they decide to implement this, it would take like at least 2 years from now…
I am not sure what you mean, I guess you meant custom element like button, or extend existing one, however I can’t add any sound or object binding, only string, float, etc.
On top of that I am not sure how to handle addressables with that.
Assigning of assets in UI builder UXML attributes is, I think, a thing in Unity 2023? So the functionality is there it will just be a bit until it’s in a stable, production ready version of Unity.
The way I would approach this - especially because UI sounds are oft repeated around the place - have a global config asset (such as scriptable object + preloaded assets) and use that to create a board of sounds that can be accessed from anywhere.
Then you can just code your UI elements to pull from this sound board. Probably not the prettiest, but it should work.
Well, it would work, but it sounds like very not flexible solution.
I mean, is there any person who succesfully tried to use ui toolkit as runtime UI, and it worked? I wanted to avoid ugui nightmare, but so far it looks like I step into another one as there are so many missing features…
You should be able to reference an audio asset via a custom control, using the feature detailed here .
The main problem will be that Unity requires a GameObject to play a sound so you may need to have something like a SoundManager singleton to manage this.
Ok, this sounds like reasonable solution, however I think I am bound to 2022 for now. Also SoundManager is not a problem - from my experience it wouldn’t be sane to play sound without any audio manager anyway.