<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ue4 basics Archives - Couch Learn</title>
	<atom:link href="https://couchlearn.com/tag/ue4-basics/feed/" rel="self" type="application/rss+xml" />
	<link>https://couchlearn.com/tag/ue4-basics/</link>
	<description>Detailed Game Programming Tutorials</description>
	<lastBuildDate>Sat, 25 Jan 2025 17:34:10 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.5</generator>

<image>
	<url>https://couchlearn.com/wp-content/uploads/2020/05/cropped-logolarge-32x32.png</url>
	<title>ue4 basics Archives - Couch Learn</title>
	<link>https://couchlearn.com/tag/ue4-basics/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to use Timers in Unreal Engine 5</title>
		<link>https://couchlearn.com/how-to-use-timers-in-unreal-engine-5/</link>
					<comments>https://couchlearn.com/how-to-use-timers-in-unreal-engine-5/#respond</comments>
		
		<dc:creator><![CDATA[Matt]]></dc:creator>
		<pubDate>Wed, 16 Nov 2022 22:00:18 +0000</pubDate>
				<category><![CDATA[UE4 Basics]]></category>
		<category><![CDATA[Unreal Basics]]></category>
		<category><![CDATA[Unreal Engine]]></category>
		<category><![CDATA[Unreal Engine 4]]></category>
		<category><![CDATA[Unreal Engine 5]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[easy difficulty]]></category>
		<category><![CDATA[ue4]]></category>
		<category><![CDATA[ue4 basics]]></category>
		<category><![CDATA[ue4 timer]]></category>
		<category><![CDATA[ue5 timer]]></category>
		<category><![CDATA[unreal engine]]></category>
		<category><![CDATA[unreal engine 4]]></category>
		<category><![CDATA[unreal engine 4 timer]]></category>
		<category><![CDATA[unreal engine 5]]></category>
		<category><![CDATA[unreal engine 5 timer]]></category>
		<guid isPermaLink="false">https://couchlearn.com/?p=1383</guid>

					<description><![CDATA[<p>Timers are one of the best ways to run blueprint code periodically without using Event Tick. Unreal Engine will trigger your event or function automatically <a class="mh-excerpt-more" href="https://couchlearn.com/how-to-use-timers-in-unreal-engine-5/" title="How to use Timers in Unreal Engine 5">[...]</a></p>
<p>The post <a href="https://couchlearn.com/how-to-use-timers-in-unreal-engine-5/">How to use Timers in Unreal Engine 5</a> appeared first on <a href="https://couchlearn.com">Couch Learn</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Timers are one of the best ways to run blueprint code periodically without using Event Tick. Unreal Engine will trigger your event or function automatically at the time set instead of constantly polling your functionality every frame.<br><br><strong>Using timers can prevent actors reducing your game&#8217;s frame rate if implemented correctly.</strong><br><br>In this guide we will be learning how to use Timers in Unreal Engine 5.</p>



<h2 class="wp-block-heading">Prerequisites</h2>



<p>To understand this guide and implement timers into your project, you will need to know how to use custom events and functions in Unreal Engine 5 before starting.</p>



<p><a href="https://couchlearn.com/how-to-use-custom-events-in-unreal-engine-4/">Click here to read our guide on custom events.</a></p>



<h2 class="wp-block-heading">How to create Blueprint Timers</h2>



<h3 class="wp-block-heading">Basic Timer Settings</h3>



<p>Before we create our timer, we will look at the basic timer settings that all timers have. These allow us to set the frequency of the timer and if the timer repeats or not.<br><br>The green <strong>Time </strong>pin is the time Unreal Engine will wait to call your event. <strong>If this value is less than or equal to 0, the timer will be cleared and will not call the event.</strong></p>



<figure class="wp-block-image size-large"><img decoding="async" width="245" height="180" src="https://couchlearn.com/wp-content/uploads/2021/01/image-13.png" alt="Setting the timer Time value. This sets the frequency of your timer." class="wp-image-1390"/></figure>



<p>The <strong>Looping</strong> check box will repeat the timer if set to <strong>true </strong>and only run once if set to <strong>false</strong>. Ticking this box is best for functionality that you want to run repeatedly.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="243" height="178" src="https://couchlearn.com/wp-content/uploads/2021/01/image-14.png" alt="Setting the Looping value of the timer. This will loop at the frequency set if true." class="wp-image-1391"/></figure>



<h3 class="wp-block-heading">Timer by Event</h3>



<p>When you want to create a timer that uses a custom event in the event graph, you need to use Set Timer by Event.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="241" height="176" src="https://couchlearn.com/wp-content/uploads/2021/01/image-10.png" alt="Creating a new timer by event" class="wp-image-1385"/></figure>



<p>As shown below, your custom events can be connected using the red event delegate square. Any custom event are connected to this pin to trigger on the time set. Only one event is connected at a time.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="516" height="268" src="https://couchlearn.com/wp-content/uploads/2021/01/image-12.png" alt="Connecting the timer to the event" class="wp-image-1389" srcset="https://couchlearn.com/wp-content/uploads/2021/01/image-12.png 516w, https://couchlearn.com/wp-content/uploads/2021/01/image-12-300x156.png 300w" sizes="(max-width: 516px) 100vw, 516px" /></figure>



<h3 class="wp-block-heading">Timer by Function</h3>



<p>If you want to use a function instead of an event delegate, we have the Timer by Function Name blueprint node. This has function name and object pins replacing the red delegate pin.<br><br>Object is the reference to the object that you want to run the function on (e.g. FirstPersonCharacter or your own custom actors). <strong>If you want to run the function on this actor, you can leave this pin empty.</strong><br><br>&#8220;Function Name&#8221; is the name of the function found in the function list in your object.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="285" height="219" src="https://couchlearn.com/wp-content/uploads/2021/01/image-11.png" alt="Creating a timer with a function" class="wp-image-1387"/></figure>



<p>In this example we have created a new function in the My Blueprint panel on the left of the blueprint editor. Our new function is called <strong>MyCustomFunction</strong>.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="289" height="216" src="https://couchlearn.com/wp-content/uploads/2021/01/image-17.png" alt="Creating a new function in the blueprint editor" class="wp-image-1395"/></figure>



<p>Now our function has been created, we then add the functions name into the Function Name pin.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="301" height="236" src="https://couchlearn.com/wp-content/uploads/2021/01/image-16.png" alt="Setting a new timer's function name to the function we created in the previous step." class="wp-image-1394"/></figure>



<p><strong>The blueprint node above now run MyCustomFunction after 5 seconds without looping.</strong></p>



<h3 class="wp-block-heading">Saving the Timer</h3>



<p>If you want to change any properties about a timer, you need to save a reference to the return value. The easiest way to do this is to drag from the return value and click Promote to Variable.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="787" height="295" src="https://couchlearn.com/wp-content/uploads/2021/01/image-20.png" alt="Promoting the return value of the new timer to a variable for use later." class="wp-image-1400" srcset="https://couchlearn.com/wp-content/uploads/2021/01/image-20.png 787w, https://couchlearn.com/wp-content/uploads/2021/01/image-20-300x112.png 300w, https://couchlearn.com/wp-content/uploads/2021/01/image-20-768x288.png 768w" sizes="(max-width: 787px) 100vw, 787px" /></figure>



<h3 class="wp-block-heading">Pausing and Unpausing Timers</h3>



<p>Now we have a reference to our timer, we can pause and un-pause the timer. The nodes below show the handle and function versions of pausing and unpausing your timer.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="199" height="91" src="https://couchlearn.com/wp-content/uploads/2021/01/image-18.png" alt="Pausing the timer by handle" class="wp-image-1397"/></figure>



<figure class="wp-block-image size-large"><img decoding="async" width="212" height="94" src="https://couchlearn.com/wp-content/uploads/2021/01/image-21.png" alt="Unpausing the timer by handle" class="wp-image-1402"/></figure>



<p>Function timers can be paused and unpaused using the function name and do not need a timer handle.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="247" height="152" src="https://couchlearn.com/wp-content/uploads/2021/01/image-19.png" alt="Pausing the timer by function name" class="wp-image-1398"/></figure>



<figure class="wp-block-image size-large"><img decoding="async" width="262" height="155" src="https://couchlearn.com/wp-content/uploads/2021/01/image-23.png" alt="Un pausing the timer by function name" class="wp-image-1405"/></figure>



<h3 class="wp-block-heading">Removing a Timer</h3>



<p>When you need a timer to stop, use the clear and invalidate timer blueprint nodes. These nodes will stop the timer and destroy the specified handle object.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="278" height="92" src="https://couchlearn.com/wp-content/uploads/2021/01/image-24.png" alt="Clearing and invalidating the timer by handle" class="wp-image-1407"/></figure>



<p>When using a Function Timer, you will need to clear and invalidate the timer separately if you want to use a function name.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="457" height="161" src="https://couchlearn.com/wp-content/uploads/2021/01/image-30.png" alt="Clearing the timer by function name then invalidating the handle separately" class="wp-image-1417" srcset="https://couchlearn.com/wp-content/uploads/2021/01/image-30.png 457w, https://couchlearn.com/wp-content/uploads/2021/01/image-30-300x106.png 300w" sizes="(max-width: 457px) 100vw, 457px" /></figure>



<h3 class="wp-block-heading">Checking a Timer&#8217;s Status</h3>



<p>With the handle or function name, you can check various properties about a timer.<br><br>Firstly we have Does Timer Exist. These nodes check if the timer exists in memory. <strong>If the timer is cleared and invalidated this value is false.</strong></p>



<figure class="wp-block-image size-large"><img decoding="async" width="286" height="209" src="https://couchlearn.com/wp-content/uploads/2021/01/image-31.png" alt="Checking if the timer exists by handle or by function name" class="wp-image-1418"/></figure>



<p>Is Timer Active will return true if the handle or function name has a timer that is actively running and exists.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="292" height="210" src="https://couchlearn.com/wp-content/uploads/2021/01/image-28.png" alt="Checking if the timer is active by function name or handle" class="wp-image-1414"/></figure>



<p>&#8220;Is Timer Paused&#8221; returns true if the timer is not actively running but does exist.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="292" height="215" src="https://couchlearn.com/wp-content/uploads/2021/01/image-32.png" alt="Checking if the timer is paused by function name or handle" class="wp-image-1419"/></figure>



<h3 class="wp-block-heading">Conclusion</h3>



<p>Now you have all the knowledge to use timers in your blueprint code in Unreal Engine 5!<br><br>Having all of these nodes at your disposal allows code and functionality to run at specific times and at certain frequencies. This will overall improve the readability of your code and can bring great performance gains. We recommend setting the Time value to 0.1 or 0.05 seconds instead of running every frame on tick.<br><br>Further reading:<br><a href="https://docs.unrealengine.com/4.26/en-US/InteractiveExperiences/UseTimers/">In depth use of timers with gameplay example from Unreal Engine documentation<br></a><a href="https://docs.unrealengine.com/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/Timers/index.html">Click here to read how C++ Timers work in Unreal Engine</a></p>
<p>The post <a href="https://couchlearn.com/how-to-use-timers-in-unreal-engine-5/">How to use Timers in Unreal Engine 5</a> appeared first on <a href="https://couchlearn.com">Couch Learn</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://couchlearn.com/how-to-use-timers-in-unreal-engine-5/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to use Custom Events in Unreal Engine 4</title>
		<link>https://couchlearn.com/how-to-use-custom-events-in-unreal-engine-4/</link>
					<comments>https://couchlearn.com/how-to-use-custom-events-in-unreal-engine-4/#respond</comments>
		
		<dc:creator><![CDATA[Matt]]></dc:creator>
		<pubDate>Sun, 10 Jan 2021 23:34:09 +0000</pubDate>
				<category><![CDATA[Easy Difficulty]]></category>
		<category><![CDATA[UE4 Basics]]></category>
		<category><![CDATA[Unreal Basics]]></category>
		<category><![CDATA[Unreal Engine]]></category>
		<category><![CDATA[ue4 basics]]></category>
		<category><![CDATA[ue4 custom event]]></category>
		<category><![CDATA[unreal custom event]]></category>
		<category><![CDATA[unreal engine]]></category>
		<category><![CDATA[unreal engine 4]]></category>
		<category><![CDATA[unreal engine 4 basics]]></category>
		<category><![CDATA[unreal engine 4 custom event]]></category>
		<category><![CDATA[unreal engine basics]]></category>
		<guid isPermaLink="false">https://couchlearn.com/?p=1421</guid>

					<description><![CDATA[<p>An essential part of developing games with Unreal Engine 4 is learning Custom Events. Custom events are used to run a set of blueprint nodes <a class="mh-excerpt-more" href="https://couchlearn.com/how-to-use-custom-events-in-unreal-engine-4/" title="How to use Custom Events in Unreal Engine 4">[...]</a></p>
<p>The post <a href="https://couchlearn.com/how-to-use-custom-events-in-unreal-engine-4/">How to use Custom Events in Unreal Engine 4</a> appeared first on <a href="https://couchlearn.com">Couch Learn</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>An essential part of developing games with Unreal Engine 4 is learning Custom Events. <br><br><strong>Custom events are used to run a set of blueprint nodes on demand.</strong><br><br>Custom events are different from Functions as they can contain delay nodes and are created in the event graph.<br><br>In this guide we are learning how to create, setup and call custom events in Unreal Engine 4.</p>



<h3 class="wp-block-heading">Creating the Custom Event</h3>



<p>To create a custom event, right click anywhere in your actor&#8217;s event graph and write &#8220;Custom Event&#8221;.<br><br>Then click &#8220;Add Custom Event&#8221;.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="410" height="184" src="https://couchlearn.com/wp-content/uploads/2021/01/image-33.png" alt="Adding the custom event" class="wp-image-1422" srcset="https://couchlearn.com/wp-content/uploads/2021/01/image-33.png 410w, https://couchlearn.com/wp-content/uploads/2021/01/image-33-300x135.png 300w" sizes="(max-width: 410px) 100vw, 410px" /></figure>



<p>Once created, name the new custom event. <br><br><strong>It&#8217;s good practise to name your custom event based on its purpose.</strong></p>



<figure class="wp-block-image size-large"><img decoding="async" width="189" height="116" src="https://couchlearn.com/wp-content/uploads/2021/01/image-34.png" alt="Naming the newly created custom event" class="wp-image-1423"/></figure>



<p>Your event has now been created! <br><br>For this guide we named our custom event &#8220;My Custom Event&#8221;.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="176" height="92" src="https://couchlearn.com/wp-content/uploads/2021/01/image-35.png" alt="Created event named &quot;My Custom Event&quot;" class="wp-image-1424"/></figure>



<h3 class="wp-block-heading">Adding Inputs</h3>



<p>Similar to functions, custom events can have input variables attached to them.<br><br><strong>These are used to send information to the nodes running from the custom event.</strong><br><br>To add an input firstly click your custom event in the event graph and look to the right side of the screen.<br><br>Click the &#8220;New Parameter&#8221; button shown below to add a new variable to the inputs list.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="381" height="279" src="https://couchlearn.com/wp-content/uploads/2021/01/image-40.png" alt="Adding a new input to the custom event" class="wp-image-1432" srcset="https://couchlearn.com/wp-content/uploads/2021/01/image-40.png 381w, https://couchlearn.com/wp-content/uploads/2021/01/image-40-300x220.png 300w" sizes="(max-width: 381px) 100vw, 381px" /></figure>



<p>Then change the name of the input. The left side text box is the name that will be displayed inside the custom event.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="378" height="267" src="https://couchlearn.com/wp-content/uploads/2021/01/image-41.png" alt="Renaming the added input variable" class="wp-image-1433" srcset="https://couchlearn.com/wp-content/uploads/2021/01/image-41.png 378w, https://couchlearn.com/wp-content/uploads/2021/01/image-41-300x212.png 300w" sizes="(max-width: 378px) 100vw, 378px" /></figure>



<p>On the right side we can then change the input variables type. <br><br>We are changing this variable from Boolean to String. This means we can use text values in our input.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="484" height="597" src="https://couchlearn.com/wp-content/uploads/2021/01/image-43.png" alt="Changing the new variable to be a string" class="wp-image-1435" srcset="https://couchlearn.com/wp-content/uploads/2021/01/image-43.png 484w, https://couchlearn.com/wp-content/uploads/2021/01/image-43-243x300.png 243w" sizes="(max-width: 484px) 100vw, 484px" /><figcaption>When making your own custom events you can use any of the variable types shown.</figcaption></figure>



<p>The finished custom event input should now look like this.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="382" height="266" src="https://couchlearn.com/wp-content/uploads/2021/01/image-44.png" alt="finished input variables for the custom event" class="wp-image-1437" srcset="https://couchlearn.com/wp-content/uploads/2021/01/image-44.png 382w, https://couchlearn.com/wp-content/uploads/2021/01/image-44-300x209.png 300w" sizes="(max-width: 382px) 100vw, 382px" /></figure>



<p>The custom event in the event graph will now look like this.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="177" height="123" src="https://couchlearn.com/wp-content/uploads/2021/01/image-45.png" alt="finished custom event" class="wp-image-1439"/></figure>



<h3 class="wp-block-heading">Using your Custom Event</h3>



<p>Now that are custom event is created and the input variable has been setup, we can now create a &#8220;Print String&#8221; node to display the value of &#8220;My New Input&#8221; on the screen.<br><br><strong>This is the easiest way to test if the custom event is working correctly.</strong></p>



<figure class="wp-block-image size-large"><img decoding="async" width="611" height="189" src="https://couchlearn.com/wp-content/uploads/2021/01/image-46.png" alt="Creating a print string node to test the custom event input value." class="wp-image-1440" srcset="https://couchlearn.com/wp-content/uploads/2021/01/image-46.png 611w, https://couchlearn.com/wp-content/uploads/2021/01/image-46-300x93.png 300w" sizes="(max-width: 611px) 100vw, 611px" /></figure>



<p>Once the &#8220;Print String&#8221; node is created, connect the &#8220;My New Input&#8221; variable from your custom event to the In String pin on the Print String node.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="329" height="159" src="https://couchlearn.com/wp-content/uploads/2021/01/image-48.png" alt="Connecting the input variable to the In String value on the print string." class="wp-image-1443" srcset="https://couchlearn.com/wp-content/uploads/2021/01/image-48.png 329w, https://couchlearn.com/wp-content/uploads/2021/01/image-48-300x145.png 300w" sizes="(max-width: 329px) 100vw, 329px" /></figure>



<p>To run your custom event simply create a &#8220;Event BeginPlay&#8221; node, drag from the execution pin and type the name of your new custom event. In our case this is &#8220;My Custom Event&#8221;.<br><br>As your custom event is connected to an execution pin, it is now being called by the other event.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="616" height="156" src="https://couchlearn.com/wp-content/uploads/2021/01/image-36.png" alt="On begin play calling the new custom event." class="wp-image-1425" srcset="https://couchlearn.com/wp-content/uploads/2021/01/image-36.png 616w, https://couchlearn.com/wp-content/uploads/2021/01/image-36-300x76.png 300w" sizes="(max-width: 616px) 100vw, 616px" /></figure>



<p>Now that your custom event is being called by the BeginPlay event you can see the input variable. <br><br><strong>This input variable pin can be connected to any variable with the same type.</strong></p>



<figure class="wp-block-image size-large"><img decoding="async" width="417" height="153" src="https://couchlearn.com/wp-content/uploads/2021/01/image-49.png" alt="Connecting the my custom event to the begin play node." class="wp-image-1444" srcset="https://couchlearn.com/wp-content/uploads/2021/01/image-49.png 417w, https://couchlearn.com/wp-content/uploads/2021/01/image-49-300x110.png 300w" sizes="(max-width: 417px) 100vw, 417px" /></figure>



<p>We can now write any text into the My New Input variable.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="422" height="171" src="https://couchlearn.com/wp-content/uploads/2021/01/image-50.png" alt="Writing my custom event works in the my custom event node." class="wp-image-1445" srcset="https://couchlearn.com/wp-content/uploads/2021/01/image-50.png 422w, https://couchlearn.com/wp-content/uploads/2021/01/image-50-300x122.png 300w" sizes="(max-width: 422px) 100vw, 422px" /></figure>



<h3 class="wp-block-heading">Testing the Custom Event</h3>



<p>Running the game will now show the text that we wrote in the custom event.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="398" height="239" src="https://couchlearn.com/wp-content/uploads/2021/01/image-51.png" alt="The custom event runs correctly and prints the text on the screen." class="wp-image-1446" srcset="https://couchlearn.com/wp-content/uploads/2021/01/image-51.png 398w, https://couchlearn.com/wp-content/uploads/2021/01/image-51-300x180.png 300w" sizes="(max-width: 398px) 100vw, 398px" /></figure>



<h3 class="wp-block-heading">Conclusion</h3>



<p>Now you have the knowledge to create and use custom events in Unreal Engine 4!<br><br>Custom events are an essential component of Unreal Engine and are especially important for multiplayer game creation using blueprints.<br><br>Below are a few links for the full custom event documentation and a guide for using custom events and other Unreal Engine 4 features to make a multiplayer damage and health system.<br><br><a href="https://docs.unrealengine.com/en-US/ProgrammingAndScripting/Blueprints/UserGuide/Events/Custom/index.html">Click here to read the official documentation on Custom Events in Unreal Engine 4</a><br><br><a href="https://couchlearn.com/multiplayer-damage-and-health-system-in-unreal-engine-4/">Click here to see our guide on making a multiplayer ready damage and health system with custom events.</a></p>
<p>The post <a href="https://couchlearn.com/how-to-use-custom-events-in-unreal-engine-4/">How to use Custom Events in Unreal Engine 4</a> appeared first on <a href="https://couchlearn.com">Couch Learn</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://couchlearn.com/how-to-use-custom-events-in-unreal-engine-4/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Basic First Person Line Trace in Unreal Engine 4</title>
		<link>https://couchlearn.com/basic-first-person-line-trace-in-unreal-engine-4/</link>
					<comments>https://couchlearn.com/basic-first-person-line-trace-in-unreal-engine-4/#respond</comments>
		
		<dc:creator><![CDATA[Matt]]></dc:creator>
		<pubDate>Wed, 05 Aug 2020 13:06:16 +0000</pubDate>
				<category><![CDATA[Medium Difficulty]]></category>
		<category><![CDATA[UE4 Basics]]></category>
		<category><![CDATA[Unreal Basics]]></category>
		<category><![CDATA[Unreal Engine]]></category>
		<category><![CDATA[line trace]]></category>
		<category><![CDATA[ue4]]></category>
		<category><![CDATA[ue4 basics]]></category>
		<category><![CDATA[ue4 first person]]></category>
		<category><![CDATA[ue4 first person line trace]]></category>
		<category><![CDATA[ue4 fps]]></category>
		<category><![CDATA[ue4 line trace]]></category>
		<category><![CDATA[ue4 raycast]]></category>
		<category><![CDATA[ue4 trace]]></category>
		<category><![CDATA[unreal engine]]></category>
		<category><![CDATA[unreal engine 4]]></category>
		<category><![CDATA[unreal engine fps]]></category>
		<guid isPermaLink="false">https://couchlearn.com/?p=1215</guid>

					<description><![CDATA[<p>In this guide we will explain what a Line Trace is an how to create a Basic First Person Line Trace in Unreal Engine 4 <a class="mh-excerpt-more" href="https://couchlearn.com/basic-first-person-line-trace-in-unreal-engine-4/" title="Basic First Person Line Trace in Unreal Engine 4">[...]</a></p>
<p>The post <a href="https://couchlearn.com/basic-first-person-line-trace-in-unreal-engine-4/">Basic First Person Line Trace in Unreal Engine 4</a> appeared first on <a href="https://couchlearn.com">Couch Learn</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In this guide we will explain what a Line Trace is an how to create a Basic First Person Line Trace in Unreal Engine 4<br><br><strong>This guide builds upon the First Person Example template built into Unreal Engine 4.</strong></p>



<h3 class="wp-block-heading">How a Line Trace Works</h3>



<p>A line trace is a way to check if an object is intersecting a line. The hit data is then broken down access more information such as location of hit, normal of hit. the actor that was hit and distance from hit.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="719" height="480" src="https://couchlearn.com/wp-content/uploads/2020/08/image-22.png" alt="An example of a line trace hitting a first person character" class="wp-image-1229" srcset="https://couchlearn.com/wp-content/uploads/2020/08/image-22.png 719w, https://couchlearn.com/wp-content/uploads/2020/08/image-22-300x200.png 300w" sizes="(max-width: 719px) 100vw, 719px" /></figure>



<h3 class="wp-block-heading">Different Types of Line Traces</h3>



<p>&#8220;Line Trace for Objects&#8221; checks an intersection with a specific collision object type. (WorldStatic, WorldDynamic, Pawn, Ragdoll, PhysicsActor, etc)</p>



<figure class="wp-block-image size-large"><img decoding="async" width="381" height="465" src="https://couchlearn.com/wp-content/uploads/2020/08/image-23.png" alt="Calculate a line trace by collision object type" class="wp-image-1230" srcset="https://couchlearn.com/wp-content/uploads/2020/08/image-23.png 381w, https://couchlearn.com/wp-content/uploads/2020/08/image-23-246x300.png 246w" sizes="(max-width: 381px) 100vw, 381px" /></figure>



<p>&#8220;Line Trace by Channel&#8221; checks for an intersection with a specific line trace collision channel. (Visibility and Camera are the default options)</p>



<figure class="wp-block-image size-large"><img decoding="async" width="350" height="383" src="https://couchlearn.com/wp-content/uploads/2020/08/image-24.png" alt="Calculate a line trace by trace channel" class="wp-image-1231" srcset="https://couchlearn.com/wp-content/uploads/2020/08/image-24.png 350w, https://couchlearn.com/wp-content/uploads/2020/08/image-24-274x300.png 274w" sizes="(max-width: 350px) 100vw, 350px" /></figure>



<p>&#8220;Line Trace by Channel&#8221; checks for an intersection with a specific collision profile by name. (These can be viewed and created in the collision tab of the project settings)</p>



<figure class="wp-block-image size-large"><img decoding="async" width="349" height="353" src="https://couchlearn.com/wp-content/uploads/2020/08/image-25.png" alt="Calculate a line trace by collision profile" class="wp-image-1232" srcset="https://couchlearn.com/wp-content/uploads/2020/08/image-25.png 349w, https://couchlearn.com/wp-content/uploads/2020/08/image-25-297x300.png 297w" sizes="(max-width: 349px) 100vw, 349px" /></figure>



<h3 class="wp-block-heading">How to Calculate the First Person Line Trace</h3>



<p>All line traces have the same basic setup. The nodes below setup the vector maths required to check for any collisions wherever the camera is located and facing.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="599" height="332" src="https://couchlearn.com/wp-content/uploads/2020/08/image-17.png" alt="The universal setup for all first person line traces" class="wp-image-1222" srcset="https://couchlearn.com/wp-content/uploads/2020/08/image-17.png 599w, https://couchlearn.com/wp-content/uploads/2020/08/image-17-300x166.png 300w" sizes="(max-width: 599px) 100vw, 599px" /></figure>



<h4 class="wp-block-heading">Breaking down the Maths</h4>



<p>Firstly you use the FirstPersonCamera variable connected to the GetWorldLocation node to begin the line trace from your character&#8217;s camera position.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="227" height="129" src="https://couchlearn.com/wp-content/uploads/2020/08/image-18.png" alt="Getting the world location of the first person camera" class="wp-image-1223"/></figure>



<p>Next using the Get Controller node, get the controller rotation from the Get Control Rotation node. This will get the rotation of your camera and even works multiplayer games.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="232" height="164" src="https://couchlearn.com/wp-content/uploads/2020/08/image-19.png" alt="Getting the control rotation for multiplayer compatibility" class="wp-image-1224"/></figure>



<p>Afterwards connect the Get Control Rotation node to the Get Forward Vector node. This will get the direction your camera is facing of your camera.<br><br>Multiply this Get Forward Vector value by 5000 (Multiple Vector by Float) to get a point in space from 0,0,0 that is 5000 units away facing the direction of the camera.<br><em>(This is the distance away from the camera to check fora collision. Change this to whichever distance you need for your project).</em><br><br>Finally add the Get World Location return value of your First Person Camera to the multiplied value. This gets the point in 3D space that you are looking at 5000 units in front of your camera.</p>



<h3 class="wp-block-heading">Accessing the Hit Data</h3>



<p>Connecting the return value to a branch only allows successful line traces to be accessed. Not including this branch will cause lots of console errors when accessing the hit result data.<br><br>To access this data click and drag from the Out Hit value and create a Break Hit Result node.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="729" height="489" src="https://couchlearn.com/wp-content/uploads/2020/08/image-20.png" alt="Accessing the data from a line trace" class="wp-image-1226" srcset="https://couchlearn.com/wp-content/uploads/2020/08/image-20.png 729w, https://couchlearn.com/wp-content/uploads/2020/08/image-20-300x201.png 300w" sizes="(max-width: 729px) 100vw, 729px" /></figure>



<h3 class="wp-block-heading">The Complete First Person Line Trace</h3>



<p>This is one example of a complete first person line trace. <br><br>To use this system simply connect the execution pins to any event you want e.g. Event Tick or an event</p>



<figure class="wp-block-image size-large"><img decoding="async" width="967" height="376" src="https://couchlearn.com/wp-content/uploads/2020/08/image-16.png" alt="An example of a complete first person line trace" class="wp-image-1221" srcset="https://couchlearn.com/wp-content/uploads/2020/08/image-16.png 967w, https://couchlearn.com/wp-content/uploads/2020/08/image-16-300x117.png 300w, https://couchlearn.com/wp-content/uploads/2020/08/image-16-768x299.png 768w" sizes="(max-width: 967px) 100vw, 967px" /></figure>



<h3 class="wp-block-heading">Conclusion</h3>



<p>Your project now is setup to use a basic First Person Line Trace in Unreal Engine 4!<br><br>Your project can now detect when objects are in front of the camera. Many use this system for weapons, interacting with objects such as doors, pickups and much more!<br><br><strong>Further Reading</strong>:<br><br>Combine this line trace system with our easy AI movement guide to create computer controlled character that can interact with objects! <a href="https://couchlearn.com/easy-ai-movement-in-unreal-engine-4/">https://couchlearn.com/easy-ai-movement-in-unreal-engine-4/</a><br><br>Unreal Engine&#8217;s documentation on single line traces: <a href="https://docs.unrealengine.com/en-US/Engine/Physics/Tracing/HowTo/SingleLineTraceByChannel/index.html">https://docs.unrealengine.com/en-US/Engine/Physics/Tracing/HowTo/SingleLineTraceByChannel/index.html</a><br><br>Unreal Engine&#8217;s full documentation on traces: <a href="https://docs.unrealengine.com/en-US/Engine/Physics/Tracing/Overview/index.html">https://docs.unrealengine.com/en-US/Engine/Physics/Tracing/Overview/index.html</a></p>
<p>The post <a href="https://couchlearn.com/basic-first-person-line-trace-in-unreal-engine-4/">Basic First Person Line Trace in Unreal Engine 4</a> appeared first on <a href="https://couchlearn.com">Couch Learn</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://couchlearn.com/basic-first-person-line-trace-in-unreal-engine-4/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to use Structs in Unreal Engine 4</title>
		<link>https://couchlearn.com/how-to-use-structs-in-unreal-engine-4/</link>
					<comments>https://couchlearn.com/how-to-use-structs-in-unreal-engine-4/#comments</comments>
		
		<dc:creator><![CDATA[Matt]]></dc:creator>
		<pubDate>Sun, 20 Oct 2019 15:24:44 +0000</pubDate>
				<category><![CDATA[Easy Difficulty]]></category>
		<category><![CDATA[UE4 Basics]]></category>
		<category><![CDATA[Unreal Basics]]></category>
		<category><![CDATA[Unreal Engine]]></category>
		<category><![CDATA[ue4 basics]]></category>
		<category><![CDATA[ue4 blueprints]]></category>
		<category><![CDATA[ue4 struct]]></category>
		<category><![CDATA[ue4 structs]]></category>
		<category><![CDATA[ue4 structures]]></category>
		<category><![CDATA[unreal engine 4]]></category>
		<category><![CDATA[unreal engine 4 struct]]></category>
		<category><![CDATA[unreal engine 4 structures]]></category>
		<guid isPermaLink="false">https://couchlearn.com/?p=785</guid>

					<description><![CDATA[<p>Structures are useful for most aspects of Game Development as they are incredibly versatile. In UE4 this is no different. When we are finished, our <a class="mh-excerpt-more" href="https://couchlearn.com/how-to-use-structs-in-unreal-engine-4/" title="How to use Structs in Unreal Engine 4">[...]</a></p>
<p>The post <a href="https://couchlearn.com/how-to-use-structs-in-unreal-engine-4/">How to use Structs in Unreal Engine 4</a> appeared first on <a href="https://couchlearn.com">Couch Learn</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Structures are useful for most aspects of Game Development as they are incredibly versatile. In UE4 this is no different.</p>



<p>When we are finished, our FPS example template character will print the ammo after shooting an will remove one ammo after every shot.</p>



<h3 class="wp-block-heading">What is a Structure (Struct)</h3>



<p>In Unreal Engine 4, the struct is an <strong>easy way to create your own variable type</strong>, giving you the ability to substantially improve the organisation and access of the data in your blueprints.<br><br>One example of using a struct in your UE4 game would be to have a single struct that contains your player&#8217;s position, health, ammo and lives. <br>This then can be saved and loaded as one variable therefore streamlining the process as your game gets more complicated.</p>



<p>In this guide we will be learning how to create a structure and how to use structures in Unreal Engine 4.</p>



<h3 class="wp-block-heading">Creating the Struct</h3>



<p>To create your struct, firstly right click in the content browser and in the bottom section click on the Blueprints tab.</p>



<figure class="wp-block-image"><img decoding="async" width="149" height="308" src="https://couchlearn.com/wp-content/uploads/2019/10/image-23.png" alt="Advanced asset menu" class="wp-image-861" srcset="https://couchlearn.com/wp-content/uploads/2019/10/image-23.png 149w, https://couchlearn.com/wp-content/uploads/2019/10/image-23-145x300.png 145w" sizes="(max-width: 149px) 100vw, 149px" /></figure>



<p>Once in the Blueprints tab, find and click on the option named Struct.</p>



<figure class="wp-block-image"><img decoding="async" width="345" height="342" src="https://couchlearn.com/wp-content/uploads/2019/10/image-22.png" alt="Creating the struct" class="wp-image-860" srcset="https://couchlearn.com/wp-content/uploads/2019/10/image-22.png 345w, https://couchlearn.com/wp-content/uploads/2019/10/image-22-150x150.png 150w, https://couchlearn.com/wp-content/uploads/2019/10/image-22-300x297.png 300w" sizes="(max-width: 345px) 100vw, 345px" /></figure>



<p>Rename this new file something suitable and save. In this example, I named mine PlayerInfo.</p>



<figure class="wp-block-image"><img decoding="async" width="74" height="112" src="https://couchlearn.com/wp-content/uploads/2019/10/image-24.png" alt="New struct" class="wp-image-862"/></figure>



<h3 class="wp-block-heading">Setting up the Struct</h3>



<p>Before we can start to use our new struct we need to fill it with variable types and give them the names that we want that data to be known as.</p>



<figure class="wp-block-image"><img decoding="async" width="924" height="261" src="https://couchlearn.com/wp-content/uploads/2019/10/image-25.png" alt="Struct variable menu" class="wp-image-863" srcset="https://couchlearn.com/wp-content/uploads/2019/10/image-25.png 924w, https://couchlearn.com/wp-content/uploads/2019/10/image-25-300x85.png 300w, https://couchlearn.com/wp-content/uploads/2019/10/image-25-768x217.png 768w" sizes="(max-width: 924px) 100vw, 924px" /></figure>



<p>In my case, I have added a Vector named &#8216;Player Location&#8217;, a Float named &#8216;Player Health&#8217;, an Integer named &#8216;Player Ammo&#8217; and another Integer named &#8216;Story Progression&#8217;.</p>



<figure class="wp-block-image"><img decoding="async" width="1024" height="330" src="https://couchlearn.com/wp-content/uploads/2019/10/image-26-1024x330.png" alt="New variables inside the struct" class="wp-image-864" srcset="https://couchlearn.com/wp-content/uploads/2019/10/image-26-1024x330.png 1024w, https://couchlearn.com/wp-content/uploads/2019/10/image-26-300x97.png 300w, https://couchlearn.com/wp-content/uploads/2019/10/image-26-768x248.png 768w, https://couchlearn.com/wp-content/uploads/2019/10/image-26.png 1038w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>This struct can now be added as a new variable in our main character blueprint.</p>



<h3 class="wp-block-heading">Creating the Struct on our Player Character</h3>



<p>To access the struct, simply create a new variable in our main character blueprint and set the type to the name of your struct created earlier.</p>



<figure class="wp-block-image"><img decoding="async" width="335" height="149" src="https://couchlearn.com/wp-content/uploads/2019/10/image-28.png" alt="Adding the struct to the player" class="wp-image-866" srcset="https://couchlearn.com/wp-content/uploads/2019/10/image-28.png 335w, https://couchlearn.com/wp-content/uploads/2019/10/image-28-300x133.png 300w" sizes="(max-width: 335px) 100vw, 335px" /></figure>



<p>Compile and save your blueprint to show the values of the struct. <br><br>I have set the initial values to 100 for the player&#8217;s health and 25 for the player&#8217;s ammo.</p>



<figure class="wp-block-image"><img decoding="async" width="476" height="436" src="https://couchlearn.com/wp-content/uploads/2019/10/image-37.png" alt="Adding values to the player struct" class="wp-image-876" srcset="https://couchlearn.com/wp-content/uploads/2019/10/image-37.png 476w, https://couchlearn.com/wp-content/uploads/2019/10/image-37-300x275.png 300w" sizes="(max-width: 476px) 100vw, 476px" /></figure>



<h3 class="wp-block-heading">Accessing the Struct on our Player Character</h3>



<h4 class="wp-block-heading">Getting the Values</h4>



<p>To get the values inside our struct, simply type get and then the struct variable name. In my case I typed &#8216;get PlayerValues&#8217;.</p>



<figure class="wp-block-image"><img decoding="async" width="410" height="118" src="https://couchlearn.com/wp-content/uploads/2019/10/image-31.png" alt="Get the struct" class="wp-image-870" srcset="https://couchlearn.com/wp-content/uploads/2019/10/image-31.png 410w, https://couchlearn.com/wp-content/uploads/2019/10/image-31-300x86.png 300w" sizes="(max-width: 410px) 100vw, 410px" /></figure>



<p>From this new get node, right click the pin and click the split struct pin button. This will now expose the values inside the struct.</p>



<figure class="wp-block-image"><img decoding="async" width="257" height="261" src="https://couchlearn.com/wp-content/uploads/2019/10/image-32.png" alt="Splitting the struct pin" class="wp-image-871"/></figure>



<p>From this get node, I access the PlayerAmmo value and can then print it to the screen using the Print String node. <br><br>This will now display my ammo on screen when the Left Mouse Button is pressed.</p>



<figure class="wp-block-image"><img decoding="async" width="485" height="311" src="https://couchlearn.com/wp-content/uploads/2019/10/image-33.png" alt="Printing the ammo value" class="wp-image-872" srcset="https://couchlearn.com/wp-content/uploads/2019/10/image-33.png 485w, https://couchlearn.com/wp-content/uploads/2019/10/image-33-300x192.png 300w" sizes="(max-width: 485px) 100vw, 485px" /></figure>



<h4 class="wp-block-heading">Setting the Values</h4>



<p>To set the values inside our struct, simply type set and then the name of your struct variable. In this case I typed &#8216;Set PlayerValues&#8217;.</p>



<figure class="wp-block-image"><img decoding="async" width="410" height="118" src="https://couchlearn.com/wp-content/uploads/2019/10/image-34.png" alt="Setting the player values struct" class="wp-image-873" srcset="https://couchlearn.com/wp-content/uploads/2019/10/image-34.png 410w, https://couchlearn.com/wp-content/uploads/2019/10/image-34-300x86.png 300w" sizes="(max-width: 410px) 100vw, 410px" /></figure>



<p>From there, right click the left pin of your Set PlayerValues node and click split struct pin. This will then expose the values of your struct variable which then can be set however you want.</p>



<figure class="wp-block-image"><img decoding="async" width="180" height="187" src="https://couchlearn.com/wp-content/uploads/2019/10/image-35.png" alt="Splitting the struct pin on the set node" class="wp-image-874"/></figure>



<p>For my character, I access the struct variable and set the Player Ammo value when I have fired my weapon using the Left Mouse Button.</p>



<figure class="wp-block-image"><img decoding="async" width="1024" height="322" src="https://couchlearn.com/wp-content/uploads/2019/10/image-36-1024x322.png" alt="Setting the ammo after every shot." class="wp-image-875" srcset="https://couchlearn.com/wp-content/uploads/2019/10/image-36-1024x322.png 1024w, https://couchlearn.com/wp-content/uploads/2019/10/image-36-300x94.png 300w, https://couchlearn.com/wp-content/uploads/2019/10/image-36-768x241.png 768w, https://couchlearn.com/wp-content/uploads/2019/10/image-36.png 1038w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption> This blueprint for firing is included in the default first person template character. </figcaption></figure>



<p class="has-text-align-center"><strong>When setting your values make sure to never leave any empty as they will be overwritten!</strong><br><br><strong>In the example above I set the location, health and story progression values to the values it already stored. </strong></p>



<h3 class="wp-block-heading">Example</h3>



<p>Every time the player presses the left mouse button the bullet is shot and one bullet is taken away from the ammo. The remaining ammo is then printed on the screen.</p>



<figure class="wp-block-image"><img decoding="async" width="916" height="538" src="https://couchlearn.com/wp-content/uploads/2019/10/image-38.png" alt="Shooting with left mouse button reduces the ammo and prints the ammo on the screen." class="wp-image-877" srcset="https://couchlearn.com/wp-content/uploads/2019/10/image-38.png 916w, https://couchlearn.com/wp-content/uploads/2019/10/image-38-300x176.png 300w, https://couchlearn.com/wp-content/uploads/2019/10/image-38-768x451.png 768w" sizes="(max-width: 916px) 100vw, 916px" /></figure>



<h3 class="wp-block-heading">Conclusion</h3>



<p>Now you have a fully working struct in your project that can now be used to store your player&#8217;s current status and progress. <br><br>This setup makes your general player variables much more organised and prevents data from being hard to track down.<br><br>The struct is a key part of shrinking large areas of blueprints into compact and efficient systems. <br><br>With this setup and working you can now create your own new structs for other gameplay tasks and uses.</p>



<h4 class="wp-block-heading">Further Examples</h4>



<p>Structs are great for creating a quest system. Each quest uses the struct for its location, enemies to spawn/ be defeated, gold reward and more. <br><br>This then can easily be added to a UMG widget to display the info on screen. Furthermore this can then be saved easily to preserve the player&#8217;s progress through the quests in your game.</p>



<p>One essential use for structs is to create an utilize Data Tables.</p>



<p><a href="https://docs.unrealengine.com/en-US/Engine/Blueprints/UserGuide/Variables/Structs/index.html">To read the Unreal Engine 4 documentation on Structs click here.</a></p>
<p>The post <a href="https://couchlearn.com/how-to-use-structs-in-unreal-engine-4/">How to use Structs in Unreal Engine 4</a> appeared first on <a href="https://couchlearn.com">Couch Learn</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://couchlearn.com/how-to-use-structs-in-unreal-engine-4/feed/</wfw:commentRss>
			<slash:comments>8</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/

Page Caching using Disk: Enhanced 
Minified using Disk

Served from: couchlearn.com @ 2026-04-16 22:57:34 by W3 Total Cache
-->