<?xml version="1.0" encoding="UTF-8" standalone="yes"?><oembed><version><![CDATA[1.0]]></version><provider_name><![CDATA[Shooter Game Tutorial]]></provider_name><provider_url><![CDATA[http://shootertutorial.com]]></provider_url><author_name><![CDATA[andrzejkoloska]]></author_name><author_url><![CDATA[https://shootertutorial.com/author/andrzejkoloska/]]></author_url><title><![CDATA[UMG UI: Draw player health and&nbsp;armor]]></title><type><![CDATA[link]]></type><html><![CDATA[<p><img class="alignnone" src="https://i1.wp.com/giant.gfycat.com/FlamboyantBouncyGnat.gif" alt="" /></p>
<p>By this post I will start UMG HUD tutorials series. What I would like to accomplish in this tutorial:</p>
<ul>
<li>Display player health,</li>
<li>Display player armor,</li>
<li>It should work well on all platforms and mostly on VR,</li>
<li>It should be optimized for mobiles,</li>
</ul>
<p>Let&#8217;s start!</p>
<p><!--more--></p>
<pre><strong>This Tutorial has been created using Unreal Engine 4.8.2</strong>. 
Make sure you are working on the same version of the engine.</pre>
<p><strong>VR THEORY</strong></p>
<p>My game will support VR controller and I need to be sure that UI will work correctly on VR. When working with UMG and VR you can&#8217;t draw canvas on-screen. Currently it won&#8217;t work.</p>
<p>What you need to do is to use Widget Component which will be rendered in scene instead of canvas. Another thing when working on UI &#8211; think how player will change buttons focus using game pad.</p>
<hr />
<p><strong>UI GRAPHICS</strong></p>
<p>I&#8217;ve <a href="http://evilsystem.eu/assetstore/asset/KSPREE_UI/" target="_blank">found great package with sci-fi UI</a> graphics.</p>
<p><img class="alignnone" src="https://d2ujflorbtfzji.cloudfront.net/package-screenshot/8f7c209c-c908-429a-9dbe-5457fad227cc_orig.jpg" alt="" /></p>
<p>It will be used in this game. Basically there is small amount of UI packages out there and I encourage 2d graphics artists to create more! There is space for money there for you guys! <span class='wp-smiley wp-emoji wp-emoji-wink' title=';)'>;)</span></p>
<p>You need to be creative when working with UI. As always &#8211; take your time and learn which parts of UI graphics do you have and which kind of things can be accomplished.</p>
<p>I&#8217;m not sure how much I will get from this pack because it isn&#8217;t prepared for UMG, but we will see.</p>
<hr />
<p><strong>Creating UMG Widget</strong></p>
<p>Create new User Widget named HUD_Health and open it.</p>
<p>Recreate my hierarchy:</p>
<p><span class='embed-youtube' style='text-align:center; display: block;'><iframe class='youtube-player' type='text/html' width='640' height='390' src='https://www.youtube.com/embed/KDnpOA_iAtM?version=3&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;wmode=transparent' frameborder='0' allowfullscreen='true'></iframe></span></p>
<p>After that go to Graph and add those variables:</p>
<ul>
<li>CurrentDisplayedArmor (float),</li>
<li>CurrentDisplayedHealth (float),</li>
<li>NewArmorToDisplay (float),</li>
<li>NewHealthToDisplay (float),</li>
<li>MaxArmor (float),</li>
<li>MaxHealth (float),</li>
<li>DeltaTime (float),</li>
<li>isUpdatingHealthDisplay (bool),</li>
</ul>
<p>Create new custom event named UpdateHealth with two inputs &#8220;New Armor&#8221;, &#8220;New Health&#8221; &#8211; both floats.</p>
<p><a href="https://shootertutorial.files.wordpress.com/2015/07/updatehealthumg.jpg"><img class="alignnone wp-image-688 size-large" src="https://shootertutorial.files.wordpress.com/2015/07/updatehealthumg.jpg?w=1024&#038;h=372" alt="UpdateHealthUMG"   /></a></p>
<p>I will use Tick to animate the progress bars. You could use function bindings for this but they will tick all the time taking the CPU.</p>
<p><a href="https://shootertutorial.files.wordpress.com/2015/07/umgtick.jpg"><img class="alignnone size-medium wp-image-689" src="https://shootertutorial.files.wordpress.com/2015/07/umgtick.jpg?w=300&#038;h=141" alt="umgtick" width="300" height="141" /></a></p>
<p>Last thing: Create new function named Set Maximum Values.</p>
<p><a href="https://shootertutorial.files.wordpress.com/2015/07/setmaximumvalues.jpg"><img class="alignnone wp-image-691 size-large" src="https://shootertutorial.files.wordpress.com/2015/07/setmaximumvalues.jpg?w=1024&#038;h=301" alt="setmaximumvalues"   /></a></p>
<p>That&#8217;s all in UMG.</p>
<p><strong>UPDATING I_TakeDamage </strong></p>
<p>Open I_TakeDamage interface and add PlayerTakeDamage function with one float input Damage.</p>
<hr />
<p><strong>UPDATING GameplayCharacter</strong></p>
<p>Open GameplayCharacter and add those variables:</p>
<ul>
<li>CurrentHealth (float)</li>
<li>MaxHealth (float, default: 100)</li>
<li>CurrentArmor (float),</li>
<li>MaxArmor (float, default: 100)</li>
<li>isDead (bool)</li>
</ul>
<p>Now let&#8217;s add umg widget to components. Create two new components &#8211; SpringArm and Widget named HUD_Health.</p>
<p><a href="https://shootertutorial.files.wordpress.com/2015/07/components.jpg"><img class="alignnone size-full wp-image-690" src="https://shootertutorial.files.wordpress.com/2015/07/components.jpg?w=148&#038;h=84" alt="components" width="148" height="84" /></a></p>
<p>Make sure SpringArm is attached to FPPMesh, and HUD_Health to SpringArm.</p>
<p>SpringArm properties:</p>
<ul>
<li>Location: (X=22.266954,Y=13.166011,Z=128.156479)</li>
<li>Rotation: (Pitch=0.000000,Yaw=89.999954,Roll=-0.000000)</li>
<li>Target Arm Lenght: -33,</li>
<li>Use Pawn Control Rotation: True,</li>
<li>Enable Camera Rotation Lag: True,</li>
<li>Camera Rotation Lag Speed: 12,</li>
</ul>
<p>Widget properties:</p>
<ul>
<li>Location: (X=1.366085,Y=-0.000915,Z=-0.000003)</li>
<li>Rotation: (Pitch=0.000068,Yaw=89.999947,Roll=89.999947)</li>
<li>Scale: (X=0.030000,Y=0.031240,Z=0.074050)</li>
<li>Widget Class: HUD_Health &#8211; earlier created widget as you may guess,</li>
<li>Draw Size: 1000 x 150,</li>
<li>Collision Presets: NoCollision,</li>
</ul>
<p>The point here is to position our widget near bottom of the camera. I know it isn&#8217;t so easy but thanks to that it will work on VR, and you will have fancy lag animation <span class='wp-smiley wp-emoji wp-emoji-wink' title=';)'>;)</span> As always &#8211; take your time to position the widget!</p>
<p><a href="https://shootertutorial.files.wordpress.com/2015/07/widgetincharacter.jpg"><img class="alignnone wp-image-697 size-large" src="https://shootertutorial.files.wordpress.com/2015/07/widgetincharacter.jpg?w=1024&#038;h=670" alt="widgetincharacter"   /></a></p>
<p>If you have the widget you need to set health and armor variables in both GameplayCharacter and the Widget. I will use BeginPlay for this.</p>
<p><a href="https://shootertutorial.files.wordpress.com/2015/07/pawnbeginplay.jpg"><img class="alignnone wp-image-692 size-large" src="https://shootertutorial.files.wordpress.com/2015/07/pawnbeginplay.jpg?w=1024&#038;h=278" alt="pawnbeginplay"   /></a></p>
<p>So we let know widget about health/armor variables.</p>
<p>Now let&#8217;s drive damage.</p>
<p>Implement I_TakeDamage Interface and create PlayerTakeDamage event.</p>
<p><a href="https://shootertutorial.files.wordpress.com/2015/07/playertakedamage.jpg"><img class="alignnone size-medium wp-image-693" src="https://shootertutorial.files.wordpress.com/2015/07/playertakedamage.jpg?w=300&#038;h=123" alt="playertakedamage" width="300" height="123" /></a></p>
<p>Thanks to this we have event based system connected with UMG.</p>
<hr />
<p><strong>Updating Enemy to make damage.</strong></p>
<p>Last thing left is to update Enemies so they will make damage to player. Open BP_BaseEnemy and add one new variable: Damage (float, default 25)</p>
<p>And create new function Shoot At Player with one float input &#8211; Damage.</p>
<p><a href="https://shootertutorial.files.wordpress.com/2015/07/shootatplayer.jpg"><img class="alignnone wp-image-694 size-large" src="https://shootertutorial.files.wordpress.com/2015/07/shootatplayer.jpg?w=1024&#038;h=391" alt="shootatplayer"   /></a></p>
<p>At this point we have only one enemy &#8211; Trooper. Open BP_Enemy_Tropper and in the end of Fire event call Shoot At Player.</p>
<p><a href="https://shootertutorial.files.wordpress.com/2015/07/shootatplayerintrooper.jpg"><img class="alignnone wp-image-695 size-large" src="https://shootertutorial.files.wordpress.com/2015/07/shootatplayerintrooper.jpg?w=1024&#038;h=424" alt="shootatplayerintrooper"   /></a></p>
<hr />
<p><strong>FINAL EFFECT</strong></p>
<p><span class='embed-youtube' style='text-align:center; display: block;'><iframe class='youtube-player' type='text/html' width='640' height='390' src='https://www.youtube.com/embed/vz2GRNKx1Ek?version=3&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;wmode=transparent' frameborder='0' allowfullscreen='true'></iframe></span></p>
<blockquote><p>Creating ShooterTutorial takes a lot of my free time.<br />
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=8UXM3JZGDPPPE"><img src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" alt="Buy Now Button" /><br />
</a>If you want you can help me out! I will use your donation to buy better assets packs and you will be added to Credits /Backers page as well.</p>
<p>Implementing game is taking time but writing about this is taking much more effort.</p></blockquote>
]]></html><thumbnail_url><![CDATA[https://i0.wp.com/shootertutorial.files.wordpress.com/2015/07/widgetincharacter.jpg?fit=440%2C330]]></thumbnail_url><thumbnail_height><![CDATA[287]]></thumbnail_height><thumbnail_width><![CDATA[440]]></thumbnail_width></oembed>