{"id":2125,"date":"2019-01-21T15:44:35","date_gmt":"2019-01-21T06:44:35","guid":{"rendered":"https:\/\/blog.criware.com\/?p=2125"},"modified":"2019-01-21T15:48:54","modified_gmt":"2019-01-21T06:48:54","slug":"sonifying-ammo-count-in-ue4-with-adx2","status":"publish","type":"post","link":"https:\/\/blog.criware.com\/index.php\/2019\/01\/21\/sonifying-ammo-count-in-ue4-with-adx2\/","title":{"rendered":"Sonifying Ammo Count in UE4 with ADX2"},"content":{"rendered":"<p><\/p>\n<h2>Introduction<\/h2>\n<p>Effective sound design is not just about finding a sound to fit its respective action, it is also about imparting subtle cues to the player. In designing sound for UI, it can be a massive boon to highlight, or even altogether replace these elements with informative audio cues. For example, one such UI element that is prominent in many shooting games is the ammunition counter. In these types of games, it can be helpful to give the player some sort of feedback on how low their ammo count is before they need to reload. This reduces the need for the player to look away from the action, and as a positive consequence, adds some dynamic timbral variation.<\/p>\n<p>This month we will be looking at sonifying the ammo counter of a first-person shooter game, using ADX2 and simple template in UE4.<\/p>\n<div style=\"width:800px; margin:0 auto;\">\n<div style=\"width: 800px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-2125-1\" width=\"800\" height=\"450\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/runningoutofammo-3.mp4?_=1\" \/><a href=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/runningoutofammo-3.mp4\">https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/runningoutofammo-3.mp4<\/a><\/video><\/div>\n<\/div>\n<p><a href=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/AtomCraft_1901_dynamicammo-1.zip\" rel=\"\"><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1813\" style=\"display: inline-block;\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2018\/06\/zip.png\" alt=\"zip\" width=\"80\" height=\"78\" \/><br \/>\nAtomCraft_1901_dynamicammo.zip<br \/>\n<em>This project was created using CRI Atom Craft V3.40.07<\/em><br \/>\n<\/a><\/p>\n<p><a href=\"https:\/\/unityplugin.crimiddleware.com\/wp-content\/uploads\/UE4_ADX2FPSDynamicAmmo.zip\" rel=\"\"><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1813\" style=\"display: inline-block;\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2018\/06\/zip.png\" alt=\"zip\" width=\"80\" height=\"78\" \/><br \/>\nUE4_ADX2FPSDynamicAmmo.zip<br \/>\n<em>This UE4 project was created using V4.21.1<\/em><br \/>\n<\/a><\/p>\n<p>&nbsp;<\/p>\n<p><!-- ----------------------------------------------------------1--------------------------------------------------- --><\/p>\n<h2>Setting up in Atom Craft<\/h2>\n<p>There are many different types of weapons and items which require ammunition, from single-shot bolt-action rifles, to continually firing aerosol spray cans. Although not always entirely realistic, manipulating or adding to the sound of a weapon that is in need of recharging or replacing can benefit gameplay, especially if it makes sense in context.<\/p>\n<p>For the sake of simple illustration, I have chosen to focus on creating a weapon that shoots one bullet per trigger. This will require two distinct layers &#8211; the main part of the gunshot, and a clicking sound to indicate that the player\u2019s clip is about to run out. To set this up in Atom Craft:<\/p>\n<ul>\n<li>Create a Polyphonic <strong>Cue_GunShot<\/strong> Cue<\/li>\n<li>Add Tracks to this Cue with the following Random no Repeat Sub Sequences:\n<ul>\n<li><strong>SingleShotContainer<\/strong><\/li>\n<li><strong>LowAmmoContainer<\/strong><\/li>\n<\/ul>\n<\/li>\n<li>Drop the relevant materials onto their respective Sub Sequences<\/li>\n<li>Create an AISAC Control named <strong>DynamicAmmoIndicator<\/strong>\n<ul>\n<li>Add this AISAC to <strong>LowAmmoContainer<\/strong> as a Volume Graph Type<\/li>\n<li>Create a curve as illustrated below<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2139\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-1.png\" alt=\"1-1\" width=\"1569\" height=\"348\" srcset=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-1.png 1569w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-1-300x67.png 300w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-1-768x170.png 768w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-1-1024x227.png 1024w\" sizes=\"auto, (max-width: 1569px) 100vw, 1569px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2140\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-2.png\" alt=\"1-2\" width=\"1229\" height=\"295\" srcset=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-2.png 1229w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-2-300x72.png 300w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-2-768x184.png 768w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-2-1024x246.png 1024w\" sizes=\"auto, (max-width: 1229px) 100vw, 1229px\" \/><\/p>\n<p>We can now test how this sounds in the Session Window by dragging in the <strong>Cue_GunShot<\/strong> Cue and activating the <strong>DynamicAmmoIndicator<\/strong> AISAC. This doesn\u2019t mimic gameplay, however, since the AISAC is not automatically increasing each time we playback the Cue. In order to test how this behaviour will sound and feel, we need to jump into UE4. We can finish this section off by building the Atom CueSheet Binary for this project.<\/p>\n<p>&nbsp;<\/p>\n<h2>Setting up in UE4<\/h2>\n<p>Integrating ADX2 into UE4 is a straight-forward process, and I recommend following the SDK documentation for this part as it is easy to follow and kept up-to-date.<\/p>\n<p>To facilitate quick prototyping, and for the sake of brevity, I have created a First Person Blueprint template project and set up a rudimentary ammo counter that displays on the player\u2019s gun. I have also imported\/converted <strong>CueSheet_0<\/strong> and <strong>Cue_GunShot<\/strong> into .uassets for use inside of UE4. This means that all of the actual implementation and logic for this blog can be followed solely inside the <strong>FirstPersonCharacter<\/strong> Blueprint, which can be accessed from the Content Browser in the directory:<\/p>\n<p>Content\u2192FirstPersonBP\u2192Blueprints\u2192FirstPersonCharacter.<\/p>\n<p>The first thing we need to do is create some variables:<\/p>\n<ul>\n<li><strong>AmmoCount<\/strong>: integer to store how much ammo we have left<\/li>\n<li><strong>MaxAmmo<\/strong>: integer to set how much ammo we get when we reload<\/li>\n<li><strong>AISAC Ammo Counter<\/strong>: integer to count through our <strong>DynamicAmmoIndicator<\/strong> AISAC<\/li>\n<li><strong>Ammo Ref<\/strong>: Reference to our GUI ammo widget that displays <strong>AmmoCount<\/strong><\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2142\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-3.png\" alt=\"1-3\" width=\"369\" height=\"639\" srcset=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-3.png 369w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-3-173x300.png 173w\" sizes=\"auto, (max-width: 369px) 100vw, 369px\" \/><\/p>\n<p>Our <strong>Event BeginPlay <\/strong>action loads our Cue Sheet for use within in the blueprint. The rest of the logic for this part simply initialises the UI ammo counter and sets it to the current <strong>AmmoCount <\/strong>value.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2143\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-4.png\" alt=\"1-4\" width=\"1330\" height=\"434\" srcset=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-4.png 1330w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-4-300x98.png 300w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-4-768x251.png 768w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-4-1024x334.png 1024w\" sizes=\"auto, (max-width: 1330px) 100vw, 1330px\" \/><\/p>\n<p>We then define some logic for when the player clicks their left mouse button. First, we check in the player has more than 0 in their <strong>AmmoCount<\/strong>. If they do, we subtract 1 from their <strong>AmmoCount<\/strong>, add 1 to the <strong>AISAC Ammo Counter<\/strong>, and update the player\u2019s UI ammo counter. This then continues further to play the character animation and spawn the projectile.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2144\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-5.png\" alt=\"1-5\" width=\"1438\" height=\"322\" srcset=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-5.png 1438w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-5-300x67.png 300w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-5-768x172.png 768w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-5-1024x229.png 1024w\" sizes=\"auto, (max-width: 1438px) 100vw, 1438px\" \/><\/p>\n<p>We then need to some very simple reload logic, so that we don\u2019t have to restart the game every time we want to test our blueprint. All we need to do is create an action that sets <strong>AmmoCount<\/strong> and <strong>AISAC Ammo Counter<\/strong> to their default values when the player presses a key (in this case \u201cR\u201d). This is purely for testing purposes, as a more fleshed out game would have more advanced reload logic and animation which you could even synchronise various reload sounds too.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2145\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-6.png\" alt=\"1-6\" width=\"1074\" height=\"338\" srcset=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-6.png 1074w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-6-300x94.png 300w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-6-768x242.png 768w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-6-1024x322.png 1024w\" sizes=\"auto, (max-width: 1074px) 100vw, 1074px\" \/><\/p>\n<p>The final part of our audio system involves actually playing our sound back. The execution for this is taken after our calculations, animations, and projectile spawning have occurred. This just replaces the default action included in the template, which plays a sound back using the Unreal audio engine.<\/p>\n<p>First, we place our <strong>Add Atom Component<\/strong> action, which we can click on to access more information in the Details tab. Here we can assign <strong>Cue_GunShot<\/strong> under the sound property. We can also choose to Override Attenuation here, to set custom values for spatialisation. This component will play our sound back.<\/p>\n<p>Next, we <strong>Set AISAC by Name<\/strong>, targeting the relevant Atom Component, and setting its Control Value to <strong>AISAC Ammo Counter <\/strong>divided by 10. This is because our AISAC scales from 0 to 1. The final part isn\u2019t essential, but it is helpful for debugging. We can create a Print String action to print its given input to the screen, in this case, the <strong>AISAC Ammo Counter<\/strong>. We can use the information against our Atom Craft project to decide if we want to make changes to any aspect of our AISAC.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2146\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-7.png\" alt=\"1-7\" width=\"1074\" height=\"578\" srcset=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-7.png 1074w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-7-300x161.png 300w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-7-768x413.png 768w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-7-1024x551.png 1024w\" sizes=\"auto, (max-width: 1074px) 100vw, 1074px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2147\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-8.png\" alt=\"1-8\" width=\"510\" height=\"995\" srcset=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-8.png 510w, https:\/\/blog.criware.com\/wp-content\/uploads\/2019\/01\/1-8-154x300.png 154w\" sizes=\"auto, (max-width: 510px) 100vw, 510px\" \/><br \/>\n<br \/>&nbsp;<\/p>\n<h2>Conclusion<\/h2>\n<p>And that\u2019s it! Once you have a working project set up, it becomes much easier to test new ideas. I hope that this has helped to illustrate how you can use ADX2 for creating dynamic information-driven playback. Perhaps you can think of other non-weapon systems that would benefit from this approach, such as a space-ship running low on fuel, or a torch running low on batteries.<\/p>\n<p><!-- --------------------------------------------------------2-------------------------------------------------- --><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Effective sound design is not just about finding a sound to fit its respective action, it is also about<\/p>\n","protected":false},"author":2,"featured_media":2159,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[5,7],"tags":[],"class_list":["post-2125","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-adx","category-tutorials"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/posts\/2125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/comments?post=2125"}],"version-history":[{"count":16,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/posts\/2125\/revisions"}],"predecessor-version":[{"id":2158,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/posts\/2125\/revisions\/2158"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/media\/2159"}],"wp:attachment":[{"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/media?parent=2125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/categories?post=2125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/tags?post=2125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}