I’m trying to have a feature in my game where the player can select 1 of 20 random word buttons on the screen… There are 500 random words available however… When the button is selected, I want that word played as a sound cue… What is the best practice or implementation for this sort of thing since an array of 500 string values/audio files would certainly crash the blueprint. I’m not sure of what I should do to load these files even?
Should I use an object library or some sort of structure data table combination?
There are a few ways to implement a feature, so bear with me.
One approach is to use an object library to store the sound cues for the words. An object library is a special asset in Unreal Engine that allows you to store a collection of objects, such as sound cues or textures, and access them by name or by index. You can use the object library to store the sound cues for the 500 words, and then use the “Get” node to access the sound cue for a specific word.
Another approach is to use a data table to store the words and their corresponding sound cues. A data table is a special asset in Unreal Engine that allows you to store data in a tabular format, such as a spreadsheet. You can create a data table with two columns, one for the words and one for the sound cue assets. Then, you can use the “Get Data Table Row” node to access the sound cue for a specific word.
In both cases, you’ll need to preload the sound cue assets into memory before they can be used. One way to do this is to use the “Begin Play” event to preload a certain number of sound cues into memory, and then use the “Unload Asset” node to unload sound cues that are no longer needed.
It’s worth mentioning that both object library and data table are great options to store and access your assets, but the best practice would depend on the size and complexity of your data. This is especially important if you want to expand the library of sounds further down the line.
Thanks man. That totally worked. I was confused on the way to go about it, but it all makes sense now. You have to create a structure and then put it inside a data table. That would have taken forever to figure out since I have not messed with data tables yet. I kept trying to call a structure but not getting anything to link up. I also sub to your YT and will purchase your IP hider towards the end of my project.
I’m going to fill the data table with over 500+ word references each with audio files around 50kb. That’s a sizable amount of data. My next step is to literally make this all play out and stress test it. I think the engine and any laptop (my target hardware) should be able handle this…??? This is the only feature of this particular level. Every time a player clicks a button, it will be replicated via multiplayer though. What do you think?
For anyone following along (2 years from now of course)
I’m using a structure that contains 1 sound wave variable. Then I created a data table and pick the structure that I just made. Add more rows per each word. Inside my widget I have logic that gets the text from the button and inputs into the function ‘get data table row’. I then break the structure and play the sound.
I don’t think you need to worry about performance, it is very light and should function on most hardware in the current state. You should probably test the project on the targeted hardware, and if it performs badly, perhaps you need to optimize it.