{"id":2991,"date":"2020-07-25T11:07:57","date_gmt":"2020-07-25T02:07:57","guid":{"rendered":"https:\/\/blog.criware.com\/?p=2991"},"modified":"2020-07-25T11:36:31","modified_gmt":"2020-07-25T02:36:31","slug":"time-dilation-in-ue4-using-criware-ue4-part-2","status":"publish","type":"post","link":"https:\/\/blog.criware.com\/index.php\/2020\/07\/25\/time-dilation-in-ue4-using-criware-ue4-part-2\/","title":{"rendered":"Time Dilation in UE4 using CRIWARE \u2013 UE4: Part 2"},"content":{"rendered":"<h2 style=\"font-size: 150%; font-weight: bold; margin-top: 40px;\">Introduction<\/h2>\n<p>In this month\u2019s two-part blog, we investigate some straight-forward approaches for creating audio systems that adapt to a \u201ctime dilation effect.\u201d In <a href=\"https:\/\/blog.criware.com\/index.php\/2020\/07\/25\/time-dilation-in-ue4-using-criware-atom-craft-part-1\/\">the first part<\/a>, we created the framework for our audio system in Atom Craft. In this second part, we will continue with implementation and fine-tuning in an FPS-style game in UE4.<\/p>\n<div style=\"width: 800px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-2991-1\" width=\"800\" height=\"450\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/TimeDilation-1.mp4?_=1\" \/><a href=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/TimeDilation-1.mp4\">https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/TimeDilation-1.mp4<\/a><\/video><\/div>\n<p><em>Created with CRIWARE UE4 SDK V1.27.11 and UE4 V4.24.3<\/em><\/p>\n<h2 style=\"font-size: 150%; font-weight: bold; margin-top: 40px;\">Getting Started<\/h2>\n<p>To implement our audio, we can use the FPS Blueprints template that UE4 provides, stripping out the VR-related content. As usual, the documentation is the best place to start if you need help getting the CRIWARE SDK integrated, and the CueSheet Binary imported.<\/p>\n<p>There are many different ways to reference and playback sounds, so let\u2019s import our Gunshot and Ambience Cues directly onto our <strong>First Person Character <\/strong>Blueprint, and name them accordingly. This way, we can easily reference them later. It generally doesn\u2019t make sense to place ambience on a player character, but this will make things easier for demonstration purposes. Also, the default behavior for Auto Activate is \u201ctrue,\u201d so it should playback without any further prompting.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2998\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_38_45-Window.png\" alt=\"2020-07-21 16_38_45-Window\" width=\"384\" height=\"256\" srcset=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_38_45-Window.png 384w, https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_38_45-Window-300x200.png 300w\" sizes=\"auto, (max-width: 384px) 100vw, 384px\" \/><\/p>\n<h2 style=\"font-size: 150%; font-weight: bold; margin-top: 40px;\">Time Control SFX<\/h2>\n<p>Next, let\u2019s implement the Time_SlowDown and Time_SpeedUp SFX. Using the <strong>Keyboard Events &#8211; F<\/strong> action as the control key for our ability, we can toggle the ability on and off with a <strong>Flip Flop<\/strong> action. Since it is off by default, the A output will initiate the effect, and subsequent presses will toggle the ability off and on. The <strong>Spawn Sound 2D functions<\/strong> signify this, wherein we can set our Time_SlowDown and Time_SpeedUp Cues to be played.<\/p>\n<h2 style=\"font-size: 150%; font-weight: bold; margin-top: 40px;\">Controlling AISAC &amp; Pitch using UE4\u2019s Timeline<\/h2>\n<p>These toggle states then control the playback of our <strong>Timeline<\/strong>. A <strong>Timeline<\/strong> is a handy feature for smoothly transitioning between values over time (very similar to AISAC in ADX2!). By using the Play and Reverse inputs, we can control whether the <strong>Timeline<\/strong> reads forwards or backward. Since we need slightly different values for each use-case, we can create several Float tracks, which we should name accordingly.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2999\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_36_02-Window.png\" alt=\"2020-07-21 16_36_02-Window\" width=\"1057\" height=\"401\" srcset=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_36_02-Window.png 1057w, https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_36_02-Window-300x114.png 300w, https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_36_02-Window-768x291.png 768w, https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_36_02-Window-1024x388.png 1024w\" sizes=\"auto, (max-width: 1057px) 100vw, 1057px\" \/><\/p>\n<p>The first controls the actual \u201cTime Dilation\u201d effect of our game, going from 1 (normal) to 0.25 (quarter speed). The second controls our \u201cTime Dilation AISAC<em>\u201d<\/em> curve, which corresponds to the curves we created in Atom Craft (this goes from 0 to 1). Our last curve, \u201cPitch Control,\u201d controls the pitch of our footsteps\u2019 playback. For this, we could use the same curve as our time dilation, but such low values are often a bit too extreme for pitch shifting. These all run for up to 1 second, which is set via the Length parameter.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3000\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_54_47-Window.png\" alt=\"2020-07-21 16_54_47-Window\" width=\"1531\" height=\"1043\" srcset=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_54_47-Window.png 1531w, https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_54_47-Window-300x204.png 300w, https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_54_47-Window-768x523.png 768w, https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_54_47-Window-1024x698.png 1024w, https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_54_47-Window-130x90.png 130w\" sizes=\"auto, (max-width: 1531px) 100vw, 1531px\" \/><\/p>\n<p>The <strong>Set Scalar Parameter<\/strong> and <strong>Set Global Time Dilation<\/strong> functions aren\u2019t important for our audio purposes. However, to briefly summarize, the first controls the radial blur on the screen to give the player a visual cue, and the second is a simple yet powerful function that controls the overall game speed.<\/p>\n<p>The <strong>Set Aisac by Name<\/strong> function is the important one for us. This function expects references to our Cues (Atom Components) as Targets, the name of our AISAC Control under Control Name (which we set in Atom Craft as \u201cTimeDilation\u201d), and a Control Value float to control our AISAC. The last action sets a float called <strong>\u201c<\/strong>Pitch Control,\u201d which we will access later when we implement our footsteps.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3001\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_37_14-Window.png\" alt=\"2020-07-21 16_37_14-Window\" width=\"1204\" height=\"371\" srcset=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_37_14-Window.png 1204w, https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_37_14-Window-300x92.png 300w, https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_37_14-Window-768x237.png 768w, https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_37_14-Window-1024x316.png 1024w\" sizes=\"auto, (max-width: 1204px) 100vw, 1204px\" \/><\/p>\n<h2 style=\"font-size: 150%; font-weight: bold; margin-top: 40px;\">Gunshot<\/h2>\n<p>Since the logic for gunfire playback is already included in the template, we can switch out the UE4 playback with our CRI Atom playback, using the Cue_Gunshot component as the Target (this can be dragged from the Components tab). We just need to ensure that Auto Activate is disabled in the Details tab, or else the sound will trigger when the game starts.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3002\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_39_12-Window.png\" alt=\"2020-07-21 16_39_12-Window\" width=\"913\" height=\"321\" srcset=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_39_12-Window.png 913w, https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_39_12-Window-300x105.png 300w, https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_39_12-Window-768x270.png 768w\" sizes=\"auto, (max-width: 913px) 100vw, 913px\" \/><\/p>\n<h2 style=\"font-size: 150%; font-weight: bold; margin-top: 40px;\">Footsteps<\/h2>\n<p>To trigger our footsteps, we can open up the FirstPerson_Run animation, and create some Anim Notify events on the Notifies timeline. If we right-click this Timeline\u2192Add Notify\u2026\u2192PlayAtomCue and set the Sound in our Details panel to Footsteps, we can quickly and easily trigger synchronous playback.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_42_09-Window-1.png\" alt=\"2020-07-21 16_42_09-Window\" width=\"1314\" height=\"432\" class=\"alignnone size-full wp-image-3009\" srcset=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_42_09-Window-1.png 1314w, https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_42_09-Window-1-300x99.png 300w, https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_42_09-Window-1-768x252.png 768w, https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_42_09-Window-1-1024x337.png 1024w\" sizes=\"auto, (max-width: 1314px) 100vw, 1314px\" \/><\/p>\n<p>However, this won\u2019t allow us to change the pitch based on the Pitch Control we set earlier. Instead, we can create our own Anim Notify! In the Content Browser, right-click\u2192Create Basic Asset\u2192Blueprint Class and search for Anim Notify under the All Classes tab. Name as appropriate, open it up, and in its Received_Notify function, create a Blueprint as below.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3004\" src=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_40_03-Window.png\" alt=\"2020-07-21 16_40_03-Window\" width=\"1441\" height=\"273\" srcset=\"https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_40_03-Window.png 1441w, https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_40_03-Window-300x57.png 300w, https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_40_03-Window-768x145.png 768w, https:\/\/blog.criware.com\/wp-content\/uploads\/2020\/07\/2020-07-21-16_40_03-Window-1024x194.png 1024w\" sizes=\"auto, (max-width: 1441px) 100vw, 1441px\" \/><\/p>\n<p>This Blueprint gets the Pitch Control float we previously set from our <strong>First Person Character<\/strong> and applies it to our <strong>Play Sound at Location <\/strong>function. From the dropdown next to Sound, we can select our Footsteps Cue to playback. Finally, by going back to our FirstPerson_Run animation, we can easily replace the Anim Notifies we previously created by right-clicking them and selecting Replace with Notify\u2026<\/p>\n<p>The result is a convincing prototype that offers the ability for further expansion. Using a mix of real-time audio manipulation tricks, we have created a dynamic and responsive system that gives the player auditory feedback for changes in game states.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In this month\u2019s two-part blog, we investigate some straight-forward approaches for creating audio systems that adapt to a \u201ctime<\/p>\n","protected":false},"author":2,"featured_media":3013,"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-2991","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\/2991","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=2991"}],"version-history":[{"count":9,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/posts\/2991\/revisions"}],"predecessor-version":[{"id":3032,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/posts\/2991\/revisions\/3032"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/media\/3013"}],"wp:attachment":[{"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/media?parent=2991"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/categories?post=2991"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.criware.com\/index.php\/wp-json\/wp\/v2\/tags?post=2991"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}