Explore Free Unreal Engine Tutorials – GameDev Academy https://gamedevacademy.org Tutorials on Game Development, Unity, Phaser and HTML5 Tue, 11 Apr 2023 08:31:27 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 https://gamedevacademy.org/wp-content/uploads/2015/09/cropped-GDA_logofinal_2015-h70-32x32.png Explore Free Unreal Engine Tutorials – GameDev Academy https://gamedevacademy.org 32 32 Unreal vs Godot – Should You Use One or the Other for Games? https://gamedevacademy.org/unreal-vs-godot/ Tue, 11 Apr 2023 08:31:27 +0000 https://gamedevacademy.org/?p=20276 Read more]]> Fact: your favorite video games are developed using game engines.

From well-known engines like Unity to lesser-known engines like Pico-8, game engines are an important facet of game development. They dictate the entire manner in which you go about it, and unsurprisingly, each engine has its own unique features. As you can imagine, picking the “right” game engine is very important when starting a game project.

In this article, we’re going to take a look at two very popular engines: Unreal Engine and Godot. We’ll be exploring both in terms of things such as versatility and popularity, and give you all the need-to-know info to decide which engine is the best for your personal situation.

Let’s get going!

What is a game engine?

Before we get too deep into this discussion topic, we do want to discuss a bit about what game engines actually are. For those just starting out, this is a good concept to wrap your mind around so you can interact with game dev jargon successfully.

A game engine, sometimes known as a game framework or game architecture, is a software development platform including settings that optimize and improve the experience of developing video games.

Game engines can facilitate the development of 2D and 3D games compatible with different import formats, allow developers to simulate physics, integrate AI, and use a sound engine to produce sounds.

Without game engines, the game development would be a lot more tedious. Instead of just working with your actual game mechanics or doing things like making cutscenes, you’d be stuck writing every backend structure. This includes things such as telling the computer how to even render your graphics. Making an engine is no small feat, and there’s a reason many engines are in-house and proprietary for AAA studios.

As such, game engines are one of the most important tools for development as they reduce the time and effort it takes to make a successful game (which believe us, still takes many, many hours).

BUILD YOUR OWN GAMES

Get 250+ coding courses for

$1

AVAILABLE FOR A LIMITED TIME ONLY

Versatility

As a developer, you’re free to make any type of game you wish – like 2D, 3D, AR, VR, mobile, multiplayer, and more. The game engine you choose should support the game type you wish to create, and Unreal Engine and Godot both support a wide range of games.

These include:

  • 2D. While Unreal Engine is best known for making 3D games, it can also be used to make 2D platformer games like Snake or sprite-based games. That said, Unreal Engine is definitely not the best for 2D, and can’t really be recommended. In the opposite corner, new updates to Godot 4 have significantly improved its ability to make powerful 2D games, with features such as 2D lighting, 2D light and shadow support, 2D materials, and 2D masking and clipping. Plus, Godot has a dedicated 2D engine, making it more performant in this arena (especially when it comes to physics).
  • 3D.Unreal Engine is well known for its powerful 3D game development software, with features such as pipeline integration, world-building, and simulation & effects. In comparison, while Godot does offer 3D and is powerful (with Godot 4 adding updates in this area as well), it simply can’t compare to the powerhouse that is Unreal Engine.
  • Augmented Reality (AR). There are currently no AR capabilities for Godot, whereas Unreal Engine has a high-level AR interface with features including face tracking, people occlusion, motion capture, augmented faces, and more.
  • Virtual Reality (VR). While Godot’s VR software isn’t yet up to par because of licensing issues, Unreal Engine’s VR framework is vast, allowing developers to build highly powered virtual reality apps. Unreal Engine is compatible with Oculus VR, SteamVR, Windows Mixed Reality, Samsung Gear VR, and Google VR.
  • Mobile. Both Godot and Unreal Engine have mobile capabilities. However, Unreal Engine has far more features and is compatible with Android and iOS game development.
  • Multiplayer. Godot 4 has made significant improvements to make complex multiplayer games easier for developers. The update includes improvements in scene replications and state & RSET updates. As for Unreal Engine, it also has lots of multiplayer features that are well-established, well-documented, and fairly stable.

Unreal vs Godot - Should You Use One or the Other for Games?

Coding

As a general rule of thumb, game engines tend to have one or two languages they specialize in. As such, picking the right game engine can often be tied to picking your preferred programming language as well.

In the case of Unreal Engine, there are two major choices – C++ and Blueprints Visual Scripting.

C++ is one of the most universally used and powerful programming languages out there – so you can’t go wrong with learning C++. However, and that’s a big however, it is also one of the single most difficult languages and not particularly designed for readability. Additionally, in recent years, many indie developers have moved away from C++ due to facing issues coding with it.

On the other hand, the Blueprints Visual Scripting system in Unreal is immensely powerful. With it, there’s no need to know how to code – instead you just drag and drop your functionality right onto the canvas to create logic. Thus, it’s a fantastic option for beginners who’d rather not learn tedious syntax they’ll never remember.

As for Godot, there are also two main languages here, C# and GDScript.

C# is similar to C++… except that is much more beginner-friendly. C# was designed to be a somewhat balanced language, coming with the readability of higher-level languages but still having some benefits that come only with low-level languages.

That said, Godot’s main driving force is GDScript – a scripting language developed specifically for the engine. This language, which resembles Python in some respects, is made to be easy to read and easy to use specifically for game development. That said, GDScript can’t really be used outside Godot, so learning it doesn’t benefit you if you want to go onto other platforms.

Industry Presence & Popularity

Professional game developers understand what makes a good game engine, and their use of such software can be a determining factor used to judge the competence of a software. Both Unreal Engine and Godot have made a splash in the video game industry, and both are capable of developing powerful games.

Unreal Engine is popular thanks to its high-fidelity graphics, ease of access, modularity, and just immensely powerful rendering capabilities. It’s used by both novice and expert developers, and has been used to make some of the most popular games on the market including Fortnite, Batman: Arkham City, The Matrix Awakens, and Alien: Fireteam Elite.

Likewise, Unreal Engine has been widely used even outside of games – especially when it comes to things such as film where its graphics can’t often be beaten by other software.

Godot, on the other hand, is a much younger engine. And, simply due to this youth, it’s not as established in the industry. That said – and particularly for indie developers – Godot has been quickly on the rise. Godot is also open source, which has attracted a lot of developers given the popularity of open source in general.

Regardless of its age, though, Godot has been used to create some popular games, including Lumencraft, Project Heartbeat, and Dashpong.

Unreal vs Godot - Should You Use One or the Other for Games?

Community

Game developers need a supportive community network when making a game, normally seeking support from other professionals, subreddits, YouTube channels, and more. Both Unreal and Godot have online communities offering resources for online users.

  • As an open-source project, Godot has attracted a vast community. From subreddits to a Discord chat, there’s a place for everyone in the Godot community to help each other and even contribute to the engine’s development.
  • Unreal Engine has a subreddit with over 200,000 Unreal Developers, giving information on everything you’ll ever need to know about Unreal. They also have a YouTube channel with regular updates about the game engine, tutorials, reviews, and more.
  • If you’re interested in attending in-person and online events, Unreal Engine hosts events throughout the year, designed to help fellow Unreal developers connect and share their innovations.
  • Godot also hosts various in-person and online events every year. For example, at Godot @ GDC 2023 they showcased their new games made using the Godot 4 game engine.

Both Unreal Engine and Godot also have a marketplace for assets like 3D models, textures, and systems that can be used on the engine, known as asset stores. These are largely driven by the community as well, so both have a lot to offer here.

Cost

If you’re an indie, then there’s another huge factor to consider: how much is all this going to cost you? That’s where you’re fortunate.

Unreal Engine has three licenses. With the standard license, it’s completely free to use the engine. The only catch is that once you make $1 million in revenue, you need to pay a 5% royalty fee. That said, if you do need more features, such as more developer support, Unreal also offers the Enterprise License which costs $1,500 per seat per year, or their Custom License which is quoted based on your needs.

Godot, on the other hand, is completely free. As an open-source project, there are no secret strings attached. It’s just free and will remain free far into the foreseeable future.

Tutorials & Courses

We imagine at this point, you’ve been swayed in one direction or another. So we’re going to kill two birds with one stone. First, we’re going to get you started with learning resources for both so you can jump right in. Second, we’ll give you a chance to see both engines in action by the same links. Trying both engines is the best way to figure out which one is for you!

Unreal

  • Unreal Game Development Mini-Degree, Zenva. In Zenva’s curriculum, you can start off with zero knowledge and learn Unreal Engine 5 from the ground up. You’ll master everything from the basics of the engine itself, to making portfolio-worthy projects such as FPS games, RPGs, walking simulators, and more!
  • Unreal Engine 101 – 3D Game Creation, Zenva. With this free course, you’ll learn how to get started with Unreal Engine by learning the fundamentals of manipulating game objects, as well as exploring the basics of lighting and physics and how you can incorporate these elements into gaming projects.
  • Unreal Engine 5 Beginner Tutorial – UE5 Starter Course, Unreal Sensei. This free video tutorial goes over everything needed to get started with Unreal Engine, focusing on features including nanite and lumen. This course will teach you installing Unreal, navigating its 3D viewport, creating materials and worlds, sculpting landscapes and foliage, programming using Blueprints, and more.
  • Unreal Engine Beginner Tutorial: Building Your First Game, Devslopes. This video tutorial gives you the mechanisms to build a simple game using Unreal, with the Blueprint Visual Scripting system. You’ll learn the fundamentals, including the Unreal editor itself, simple AI, events, spawning objects and effects, and the process of building games.

Godot

  • Godot 4 Game Development Mini-Degree, Zenva. This curriculum is all about giving you all the fundamentals you need to get going with Godot 4. You’ll start with the fundamentals, and then work your way to building real projects such as RTS games or RPG battle systems.
  • Godot 101 – Game Engine Foundations, Zenva. The Godot 101 course aims to teach the fundamentals of working with Godot 4, including information on how to work with Godot 4’s nodes and scenes architecture. You’ll also learn a tiny bit about getting started with GDScript.
  • Godot 4 Crash Course for Beginners – GameDev 2D Top Down Tutorial, Chris’ Tutorials. This guide teaches developers everything there is to know about the changes to Godot 4, including the tilemap tools, moving characters, and the changes to GDscript syntax.
  • Create Your First Complete 3D Game with Godot, GDQuest. This course is designed for individuals with prior coding knowledge, and takes users through the coding process from start to finish – at the end, you’ll have made your very first 3D game! Learn how to spawn monsters, make your character jump and squash, the ins and outs of animation, and much more.
  • Build a Top-Down 2D GODOT RPG in 20 Minutes, Andrew Hoffman. This video tutorial will teach you how to build a top-down 2D GODOT RPG game in just 20 minutes, including information on coding collisions, character movement, tilemaps, proper scripting, and more.

Unreal vs Godot - Should You Use One or the Other for Games?

Conclusion: Unreal vs Godot – which is better?

Let’s now turn back to our original question – should you use Unreal for your games or Godot?

The answer here is complex, and there is no one definite “right” answer. It all depends on you and your game projects. For example, if you’re making a VR game, then of course Unreal is going to be the better choice of tool. However, Godot is going to do much, much better with a 2D game, so for that Godot is the superior option.

Then again, perhaps you want the benefit of visual scripting for your 2D game, which means Unreal. Or, perhaps you just like Godot’s multiplayer features better so pick Godot for your 3D game anyway. It all comes down to personal taste and what you’re comfortable working with.

That said, it also doesn’t matter to some degree. Both engines offer a ton of resources to use, including tons of courses through which to learn and explore things.

Still, we hope this article has helped you become more informed, and we can’t wait to see the games you create with one or both engines!

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.

]]>
Beginner’s Unreal Engine Tutorial: Make Auto-Stacking Blocks https://gamedevacademy.org/stacking-blocks-unreal-tutorial/ Fri, 07 Apr 2023 06:26:08 +0000 https://gamedevacademy.org/?p=20161 Read more]]> Unreal Engine’s Blueprint Visual Scripting system vastly simplifies coding – making it easier for developers of any skill level to develop their games.

As a consequence, though, it is integral to master fundamental coding principles with the system before jumping into bigger game projects. It’s also just as important to learn how to apply these principles to simple game projects to battle-test your knowledge.

In this tutorial, we’re going to show you how to create auto-stacking blocks of boxes with a simple for loop to get you going. You’re also going to learn how to add physics to the Actors in the scene, as well as alter other core properties to familiarize yourself with.

Let’s get started!

Project Files

You can download a copy of the source code files for the project done in this tutorial here.

Note: This tutorial was made with Unreal Engine version 5.0, so if you have a higher version you might see some elements as deprecated although they still work. You’ll also need to set up the GameModeOverride to LoopsGameMode in the World Settings and select the Box as the Class in the SpawnActor Box node for the scene to run. Don’t forget to compile the project after you apply the changes!

BUILD YOUR OWN GAMES

Get 250+ coding courses for

$1

AVAILABLE FOR A LIMITED TIME ONLY

Setting Up our Project

First of all, let’s go to the Content folder and create a new Loops folder there:

Creating a folder called "Loops" in Unreal Engine

Then, we’ll create a new Basic level. Let’s name it LoopsLevel and save it in the Content > Loops folder:

Adding a new Basic level to the Loops folder

In this Loops mini-project, we want to create new Actor objects using loops, and not by dragging them by hand into the level. For that, we’ll need to create a couple of new blueprints first:

  • The Actor blueprint named Box
  • The GameMode blueprint named LoopsGameMode

We’ll save those blueprints in the Content > Loops folder as well:

Actor and GameMode blueprints added to the Loops folder

Box Blueprint

Now, let’s open the Box blueprint asset. First thing, we’ll add a new Cube component to our Box blueprint:

Adding a Cube to our Box blueprint

Cube added to the Box blueprint in Unreal Engine

Then, in the Details panel, let’s set the Material of that Cube to M_CobbleStone_Smooth material for it to look a bit more interesting:

Setting the Material of the Cube to "M_CobbleStone_Smooth"

Cube with the 'M_CobbleStone_Smooth' texture in Unreal Engine

After that, in the Cube’s Physics component, we’ll enable the Simulate Physics property, so our cube would have physics working on it:

Enabling the Simulate Physics property for the Cube object

Then, you can Compile and Save the Box blueprint.

LoopsGameMode Blueprint

Now, let’s open the LoopsGameMode blueprint and go to the Event Graph. We’ll connect the BeginPlay event node to a new ForLoop node. Here’s what the ForLoop node does:

  1. Sets the Index property to the First Index’s value
  2. If the Index is less or equal to the Last Index, this node triggers the Loop Body control flow output pin. Otherwise, the cycle is ended and the control flow goes to the Completed pin
  3. Increments the Index
  4. Goes back to step “2

Connecting the BeginPlay event to the ForLoop node in Unreal Engine

For the beginning, let’s run our loop ten times and print the index of the current iteration:

  • Set the Last Index property of the ForLoop node to 10
  • Connect the ForLoop’s Loop Body control flow to a new PrintString node
  • Connect the ForLoop’s Index pin to the In pin of the PrintString node

Printing out the index of the current iteration of our loop

Then, we will return to the LoopsLevel level. In the World Settings panel, we need to set the GameMode Override property to reference the LoopsGameMode for our changes to the LoopsGameMode to take place in the LoopsLevel level:

Making the 'GameMode Override' reference the LoopsGameMode

If you start the game now, you should see the numbers going from 0 to 10 in the top-left corner of the screen:

Numbers from 0 to 10 printed out in the top-left corner of the screen

That happens because our ForLoop node runs the Loop Body control flow for each value of the Index property from 0 to 10 inclusively:

LoopsGameMode Blueprint so far in Unreal Engine

If we’ll set the Last Index property to 1000, we’ll see numbers running from 0 to 1000 at the game start:

Setting up "Last Index" to 1000

Numbers from 0 to 1000 printed out to the screen

Using the loops allows us to save time and not copy-paste our code to be executed as many times as we want.

Spawning A Hundred Boxes

Next, let us make a hundred cubes spawn on top of each other.

First, we will delete the PrintString node from the LoopsGameMode blueprint’s EventGraph. You should have the ForLoop connected to the BeginPlay event node left:

Deleting the PrintString node from our LoopsGameMode blueprint

Then, we’ll connect the ForLoop node’s Loop Body control flow pin to a new SpawnActorFromClass node. This way, we’ll spawn objects in our loop:

Connecting the 'Loop Body' pin to a new SpawnActorFromClass node in Unreal Engine

Next, in the SpawnActor node, we’ll set the Class property to Box, so it would spawn the Box blueprint we created earlier:

Setting "Class" to Box in the SpawnActor

Also, we’ll change the ForLoop’s Last Index property from 1000 to 10, as we might want to start with a lesser amount of cubes:

Changing "Last Index" back to 10

Finally, we need to connect the SpawnActor’s Spawn Transform input pin to a new MakeTransform node, so our cubes would have information on where they should spawn:

Connecting a Make Transform node to the Actor's 'Spawn Transform' input pin

If you start the game now, you’ll see cubes “exploding” in all directions. That happens because we spawn them in the same Location at the same time and their colliders push them away from each other:

Spawning 10 cubes in Unreal Engine

If you set the ForLoop’s LastIndex to 100, you’ll have a hundred cubes flying around:

Making "Last Index" equal to 100 and spawning a 100 cubes in the level

Spawning A Tower

But how can we make the cubes spawn on top of each other? All we have to do is to iterate their Spawn Location like this:

  • Connect the MakeTransform node’s Location input pin to a new Multiply node. You have to connect the Multiply node to the Location pin first, so the Multiply node would return the Vector type
  • Connect the ForLoop node’s Index output pin to the first input pin of the Multiply node
  • Set the second input pin of the Multiply node to (0, 0, 120)

This way, we multiply the (0, 0, 120) Vector by the current Index and the cubes will be spawned every 120 vertical units. The first cube will be spawned at 0 height, the second at 120, the third at 240, and so forth:

Making the cubes spawn on top of each other

If you spawn a hundred cubes now, they will be aligned in a straight vertical line, forming a tower of sorts:

Spawning a tower of cubes in Unreal Engine

Though, that tower will crumble a second later, as soon as physics catches up with it:

Tower of cubes crumbling due to physics

Giving Boxes A Random Rotation

We can also spawn our cubes at random rotations. All we have to do for it is to connect the MakeTransform node’s Rotation input pin to a new RandomRotator node. That node will generate a random Rotation for every cube we’re spawning:

Connecting a Random Rotator node to the Make Transform's 'Rotation' input

If you start the game now, the cubes will start falling straight away, as each of them has a different rotation and they can’t stack on top of each other:

The cubes fall down as soon as spawned because they no longer stack upon one another

After The Loop Ends

We can pass the control flow once the loop ends using the Completed pin of the ForLoop node. Let’s print a message when all cubes are spawned:

  • Connect the ForLoop node’s Completed output control flow pin to a new PrintString node
  • Set the In property of the PrintString node to “All boxes have been spawned!

Printing out a message after all cubes have been spawned

Now you’ll have the “All boxes have been spawned!” message shown once all the cubes have been spawned:

Message printed to the screen in Unreal Engine

Loops Challenge

Before we finish up the tutorial, let’s have you solve a challenge! Your challenge is to create a tower of cubes that looks like a pyramid. Going from top to bottom, each cube should have a bigger scale than the previous one as seen below:

Pyramid of cubes in Unreal Engine

We suggest you use the Subtract and MakeVector nodes in that challenge. You should also remove the RandomRotator node from the LoopsGameMode Event Graph, as you don’t want those cubes to have random rotations in a pyramid:

Removing the Random Rotator node from the blueprint

Then, you should also iterate the For Loop from 0 to 10. This way your pyramid would be small and stable enough:

For Loop iteration from 0 to 10

And that’s all the hints we have for you! Now you can go and try to solve the challenge.

Challenge Solution

Once you’ve made your best at this challenge, you can check yourself with our implementation. We’ll make our cube tower look like a pyramid by scaling the cubes on the X and Y axes.

First, as we want the cube at the bottom to be the biggest, we will “flip” our Index using the Subtract node:

  • Create a new Subtract node
  • Connect the ForLoop’s Index pin to the second input pin of the Subtract node, as we want to subtract the Index from the first value
  • Set the first input pin of the Subtract node to 10. It should have the same value as the Last Index pin of the ForLoop node

This way, for the 0 Index, we’ll have 10, for the 1 Index, we’ll have 9, and so forth:

Flipping the Index to construct the base of the pyramid

Then, we’ll create the scaling Vector from that flipped Index:

  • Create a new Make Vector node
  • Connect the output pin of the Subtract node to the X and Y input pins of the MakeVector node
  • Set the Z pin of the MakeVector node to 1, so the cubes would have 100% height

This way, for the 0 Index, we’ll have the (10, 10, 1) scale, for the 1 Index, we’ll have the (9, 9, 1) scale, and so on:

Using a Vector to make the levels of the pyramid

Finally, you should connect the Return Value output pin of the MakeVector node to the Scale input pin of the MakeTransform node. This way, the scale Vector we created will be applied to the cubes:

Connecting the Make Vector to the Make Transform node

As the result, you should get a nice cube pyramid:

Final pyramid all set in the level

And if you look closely at the bottom levels of that pyramid, you’ll see that each level is just a stretched cube:

Each level of the base is formed of a single stretched cube

Conclusion

Well done on completing this tutorial!

See how easy it was to spawn whatever number of objects we want in the level scene with Unreal Engine? With this tutorial, not only did you get acquainted with the engine, but you also already coded with the Blueprints Visual Scripting System to create a pyramid of boxes! Getting confident about the simple steps within the engine will surely make your progress quicker and easier.

Moving forward, you can start tackling bigger and more complex projects, thus expanding the existing knowledge you just acquired. You can move on to adding in new features to your future scenes or dig deeper into the many features of the engine you’re interested in for your games. In any case, the foundations you’ve gathered here will provide you with a great starting point in your game-developing journey with Unreal Engine!

We wish you the best of luck in your learning path!

Want to learn more about Unreal Engine game logic? Try our complete Unreal Engine Mini-Projects course.

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.

]]>
Create Enemy AI for RTS Games – Unreal Engine Tutorial https://gamedevacademy.org/rts-enemy-ai-unreal-tutorial/ Fri, 07 Apr 2023 06:05:46 +0000 https://gamedevacademy.org/?p=19880 Read more]]> RTS games are a fantastic genre, requiring quick-decision making alongside tense action – gaining players’ attention for hours on end. BUT – it wouldn’t be unreasonable to say that RTS games only work if you have good enemy AI to go along with it.

In this tutorial, we’re specifically focusing on creating basic enemy AI units in Unreal Engine. We’re going to work on the ability of the enemy units to attack the player units in the game. The enemy units will, namely, search for the player units in range to set one of them as the current target and get to attack it until it’s destroyed.  We’ll also cover how to update the remaining player units as they are knocked down over time.

Let’s dig in!

Before You Begin & Project Files

Basic skills in Unreal Engine and its Blueprints Visual Scripting system are needed for this tutorial. Notice that you’ll need to already have a player unit blueprint in your project as this is not covered in the present tutorial. Also, we’re using inheritance to make it easier to implement both player and enemy units, which can then use or overwrite functions and values from their parent class.

You can download a copy of the source code files for the project done in the tutorial here.

Note: This tutorial was made with Unreal Engine version 5.0, so if you have a higher version you might see some elements as deprecated although they still work.

BUILD YOUR OWN GAMES

Get 250+ coding courses for

$1

AVAILABLE FOR A LIMITED TIME ONLY

Creating The Variables For The Enemy Unit

We’re going to start by creating the scripts which will set the Target Actors for the Enemy Units. We will do this in the EnemyUnit blueprint’s Event Graph.

To do it, let’s add new variables to the EnemyUnit’s Event Graph. First, we will add a new Float variable ‘DetectRange‘ with the default value of 500:

Setting up a float variable in Unreal Engine

We will use that variable to set the distance at which an Enemy Unit will notice a Player Unit. Then, we will add a new variable called PlayerUnits of type PlayerUnit. We will store all of the Player Units in that variable, so we can find the one we can reach:

Storing all Player Units in a single variable in Unreal Engine

To store all of the Player Units in that variable, we’ll have to turn that variable into an array first. Arrays allow us to store not one but several elements in one variable. Here’s how we will turn the PlayerUnits variable into an array:

  • With the PlayerUnits variable selected, go to the Details panel
  • To the right of the Variable Type selector, you should see one more selector. It should have a head as an icon
  • Click on that selector and select the Array option from the drop-down menu, to turn the PlayerUnits variable into an array of the Player Units

Turning the PlayerUnits variable into an array in Unreal Engine

Filling Up The PlayerUnits Variable

Next, we want to fill the PlayerUnits variable at the start of the game. But first, let’s take a look at the EnemyUnit’s BeginPlay node. It is connected to the Parent: BeginPlay node. That means, that at the start of the game, the EnemyUnit first runs the script the Unit blueprint has at the BeginPlay node:

EnemyUnit's BeginPlay node in Unreal Engine

Now, let’s make our EnemyUnit fill the PlayerUnit variable after running the parent’s code:

  • Connect the Parent: BeginPlay node to a new Get All Actors Of Class node
  • Set the Actor Class pin of that new node to the PlayerUnit class
  • Connect the output control flow and value pins of the Get All Actors Of Class node to a new Set Player Units node

With that script, at the start of the game, the Enemy Unit searches for all of the Player Units and saves them to the PlayerUnits variable:

Filling up the PlayerUnits variable at the start of the game

If you start the game now, you won’t see anything happen, as we don’t actually do anything with those Player Units as of now.

Creating The Target Finder Function

We’ll use the Player Units we found to select one of them that we can use as a Target. Let’s create a new function called Try Find New Target for that:

Creating the Try Find New Target function in Unreal Engine

As the game goes on, some of the Player Units might get destroyed. Let’s filter them out:

  • Connect the Try Find New Target node to a new For Each Loop node
  • Connect the Array pin of the For Each Loop node to a new Get Player Units node
  • Connect the Loop Body control flow pin of the For Each Loop node to a new Is Valid node
  • Connect the Array Element pin of the For Each Loop node to the Input Object pin of the Is Valid node

This way, we loop through each of the Player Units, check which of them still exists, and fire the Is Valid pin for them:

Updating the PlayerUnits variable in Unreal Engine

Then, we’ll find the Player Unit which is close enough to our Enemy Unit:

  • Connect the Is Valid pin of the Is Valid node to a new Branch node
  • Create a new Get Distance To node
  • Connect the Array Element pin of the For Each Loop node to the Other Actor pin of the Get Distance To node
  • Connect the Return Value pin of the Get Distance To node to a new Less Equal node
  • Connect the second input pin of the Less Equal node to a new Get Detect Range node
  • Connect the output pin of the Less Equal node to the Condition pin of the Branch node

This way, we’re checking the valid Player Units on being closer than the Detect Range to our Enemy Unit. For those close Player Units, the Branch node will fire the True pin:

Detecting the closest Player Unit to a given Enemy Unit in Unreal Engine

Next, we will set that close valid Player Unit as a Target:

  • Connect the True pin of the Branch node to a new Set Target node
  • Connect the Array Element pin of the For Each Loop to the second Target pin of the Set Target node

Setting the valid Player Unit as Target

Finally, we will make the Try Find New Target function stop after finding the Target. Otherwise, we’ll do unnecessary computations on the rest of the PlayerUnits array. To stop this function, connect the output control flow pin of the Set Target node to a new Return Node:

Stopping the Try Find New Target function after the Target gets set

Finishing Up The Enemy Unit Blueprint

So far, we’ve created variables and a function required for the Enemy AI. Let’s hook them up now:

  • Open the EnemyUnit’s Event Graph
  • Connect the Parent: Tick node output control flow pin to a new Is Valid node
  • Connect the Input Object pin of the Is Valid node to a new Get Attack Target node
  • Connect the Is Not Valid pin of the Is Valid node to a new Try Find New Target node

This way, when our Enemy Unit doesn’t have a valid Attack Target, it will try to find a new one:

Enemy Unit finding a new Target in Unreal Engine

As our Enemy Unit is inherited from the base Unit, once it has the Attack Target set, it will use the parent’s functions to move to the Target and attack it.

Testing The Enemy AI

Now, let’s get back to the GameLevel level (which we already have made) and test the changes we’ve made:

  • Start the game
  • Select the Player Unit by clicking on it with the left mouse button
  • Go close to the Enemy Unit by clicking on it with the right mouse button
  • The Enemy Unit should run to the Player Unit and attack it until the Player Unit is destroyed

Testing the enemy AI in Unreal Engine

Let’s then create a few more copies of the Enemy and Player Units, put them in different positions, and test how they work together:

Testing the game with more units in Unreal Engine

We see that the units are behaving as expected, the Enemy Units are chasing after the Player Units within range and attacking them until they are destroyed.

Conclusion

Congratulations on reaching the end of this tutorial!

You now have a basic enemy AI ready to go for your Unreal Engine RTS projects. Of course, there are more ways to expand on this concept. For example, you can add more advanced combat strategies, new types of attacks or different sorts of units, and smoother map navigation. There are a bunch of ways for you to keep improving your game here!

Regardless, though, these skills will form a good foundation you can also apply to other genres as well – only your imagination is stopping you with Unreal!

We wish you the best of luck in your future projects!

Want to learn more about strategy games in Unreal Engine? Try our complete Build an RTS Game with Unreal Engine course.

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.

]]>
Introduction to Actors, Lights, & Physics in Unreal Engine https://gamedevacademy.org/unreal-engine-physics-lights-actors-tutorial/ Fri, 07 Apr 2023 05:46:32 +0000 https://gamedevacademy.org/?p=20061 Read more]]> Unreal Engine is a powerful and popular engine, and since the release of Unreal Engine 5, interest in learning to develop with it has skyrocketed.

In this Unreal Engine tutorial, we’ll take a look at three important features of the engine: actors, lights, and physics.

Actors are the very foundation of every object in our game, and so we’re going to see how to configure their properties, scale them, rotate them, and more. Following, you’ll learn how to set up the lighting environment in your scene using the various types of lights available in the engine. And lastly, we’ll cover how to apply physics to the objects in the scene and how to make them interact with each other in the game.

Let’s get started!

Project Files

You can download a copy of the source code files for the project done in this tutorial here.

Note: This tutorial was made with Unreal Engine version 5.0, so if you have a higher version you might see some elements as deprecated (although they still work).

BUILD YOUR OWN GAMES

Get 250+ coding courses for

$1

AVAILABLE FOR A LIMITED TIME ONLY

Creating An Actor in Unreal Engine

An Actor is an object inside of a level that can have a position in 3D space.

If you look in the Outliner panel, you can see a bunch of different Actors with different types, such as Directional Light, SkyAtmosphere, and others. Despite having different types, all of them, besides the Folder and World types, are Actors on the base level:

Actors types in Unreal Engine

Then, there is the Add button in the Main Toolbar over the Level Viewport. Clicking on it will open the menu in which you can select which type of Actor you want to create. There are Basic, Lights, Shapes, and other groups of Actors:

Creating an Actor in Unreal Engine

For this example, let’s create the Shapes > Sphere Actor:

Creating a Sphere Actor in Unreal Engine

Overview Of An Actor

You will have the Sphere object created in your level:

View of the Sphere Actor object in Unreal Engine

In the Outliner panel, you can see that the Sphere is a StaticMeshActor, just like the Floor object. The StaticMeshActoris just a 3D model that is rendered at the level. It also has the Physics and Collision components:

StaticMeshActors in Unreal Engine

With the Sphere object selected, you can go to the Details panel and change the properties of the Sphere’s components. For example, you can go to the Materials component and set the Sphere’s material to the M_Brick_Clay_New material:

Changing the material of the sphere in Unreal Engine

This will make our Sphere look like a sphere of bricks:

Sphere of bricks appearance due to change of the sphere's material

Then, in the Physics component, we can change whether our Sphere is affected by gravity by changing the Enable Gravity property’s value:

Enabling gravity for our Sphere in Unreal Engine

Next, in the Collision component, we can set how our Sphere collides with other objects. You can set whether it receives collider overlap events or if it can be stepped on, and many other things:

Collision settings for the Sphere object

Each type of Actor has its own set of components and properties to tune them to your needs. You can even create your own types of Actors, for example, for the bullet projectiles to use in an FPS game.

How Lights Work in Unreal Engine

Directional Light

Let’s open our level as it is now:

Opening our level in Unreal Engine

In the Outliner panel on the right, you should see the Lighting folder, which contains all of the actors constructing the lighting and atmosphere in the level:

Lighting and atmosphere-related Actors in Unreal Engine

In every level in which you want to have some global lighting, coming from the sun or the moon, you should use the Directional Light actor:

Directional Light is commonly used for global lighting in Unreal Engine

If you move the Directional Light actor around the level, you will notice that nothing changes — it doesn’t matter where the Directional Light is located:

Changing the location of the Directional Light actor alters nothing in the Unreal Engine's level

Altering the position of the Directional Light in Unreal Engine

But if you change the Directional Light’s Rotation, you will see that the light color and intensity change as well. The current direction of the Directional Light can be seen in the Level Viewport as the white arrow coming out of the Directional Light’s gizmo:

Rotating the Directional Light alters the color and the intensity of the light in Unreal Engine

Different light color based on the rotation of the Directional Light actor in Unreal Engine

Let’s create a cube object to see how changing the direction of the light changes the lighting:

  • Press on the Add button at the Main Toolbar
  • Select the Shapes > Cube option
  • Move this Cube to the top of the Floor

Creating a cube object in Unreal Engine

Scene view of the cube object in Unreal Engine

You can see that the Cube’s shadow is aligned with the Directional Light’s direction:

Cube shadow aligned with the Directional Light in Unreal Engine

If you set the Directional Light’s Rotation in the Details panel to value around (0, 50, 0), you will see the sky turn black. That happens because the sky color depends on the Directional Light’s Rotation:

Black sky setting with Directional Light in Unreal Engine

By changing the Y Rotation of the Directional Light you can pretty much have the day-night cycle:

Rotating the Directional Light in Unreal Engine

Rotation is not the only property of the Directional Light you can change in the Details panel. The Intensity property in the Light component allows you to control how strong your Directional Light is:

Changing the intensity of the Directional Light in the Details panel

Changing the Intensity property of the Directional Light in Unreal Engine

You can also change the color of the light with the Light Color property. For example, setting the Light Color of the Directional Light to orange will make the whole level lit with orange:

Changing the color of the Directional Light can affect the whole level in Unreal Engine

Setting the Light Color property of the Directional Light in Unreal Engine

Then there is the Light’s Temperature property, with which you can make your light hotter or colder:

Altering the light's Temperature property in Unreal Engine

If you make the (white) light colder, the whole level will look a bit “colder”:

Colder light for the level in Unreal Engine

You can also turn the shadows on and off with the Cast Shadows property:

Enabling the Cast Shadows property in Unreal Engine

Point Light

The Directional Light is not the only light we could use. If you go to the Add > Lights menu, you will see the following lights:

  • Directional Light
  • Point Light
  • Spot Light
  • Rect Light
  • Sky Light

Lights in Unreal Engine

Let’s add a new Point Light now:

Adding a Point Light to the level in Unreal Engine

The wireframe sphere around the Point Light shows the range of this light. The Point Light works like a candle — it emits light in all directions, but the farther from the source, the weaker the light. It is also can be blocked by other objects on the level:

Range of the Point Light in Unreal Engine

As for the Directional Light, the Point Light also has the Intensity and Light Color properties that can be changed in the Details panel. For example, in the screenshot below we’ve increased the Intensity of the Point Light and set the Light Color to orange:

Altering the Intensity and Light Color properties of the Point Light

Then, by changing the Attenuation Radius property you can change the range of the Point Light. The bigger this Radius, the farther the light will go:

Attenuation Radius property for the Point Light in Unreal Engine

Point Light range in Unreal Engine

Now, let’s select the Directional Light actor and disable the Light’s Affects World property in the Details panel. This way we would be able to see only the light from our Point Light actor. The regions not affected by this light would be black:

Disabling the 'Affects World' property for the Directional Light

Only the Point Light visible in the scene

Spot Light

The next light we want to try out is the Spot Light. Let’s create one by selecting the Add > Lights > Spot Light option:

Adding a Spot Light in Unreal Engine

The Spot Light works like a flashlight or a spotlight — it emits light in a certain direction and is limited by a cone-like shape:

Spot Light emitting light to a specific direction in Unreal Engine

Besides the Temperature, Intensity, Color, and Radius, the Spot Light’s Light component has two new properties:

  • Inner Cone Angle — the angle of the hard light cone
  • Outer Cone Angle — the angle of the soft light cone

Tuning those values allows you to make your light as hard or as soft as you want:

Inner and Outer Cone Angle values for the Spot Light in Unreal Engine

Here’s what the green Spot Light directed at the Cube looks like:

Green Spot Light directed at cube in Unreal Engine

Rect Light

Now, let’s add the Rect Light to our level. To do that, select the Add > Lights > Rect Light option from the Main Toolbar:

Creating a Rect Light in Unreal Engine

The Rect Light actor emits light from the rectangular shape. If you want to have a ceiling that allows the light to “pass through” or some surface to emit the light, the Rect Light is the light for you:

The Rect Light emits light from a rectangular shape

The Rect Light has the following unique properties in the Light component:

  • Source Width and Height — the size of the light source
  • Barn Door Angle and Length — allow you to focus the light

Properties of the Rect Light in Unreal Engine

If you go to the Details panel and enable the Directional Light’s ability to Affect the World, you will see that it almost overpowers all of the other lights, because of how strong it is:

Enabling the "Affect the World" option for the Directional Light

Unreal Engine’s Physics System

Unreal Engine has its own Physics system, so making the objects have physics interactions is pretty simple. First, let’s create a new Sphere object by selecting the Add > Shapes > Sphere option from the Main Toolbar:

Creating a Sphere object in Unreal Engine

You should have the Sphere object appear in your level:

Sphere object in Unreal Engine's scene

Now, let’s go to the Details panel, and in the Materials component, change the Sphere’s material. We’re using the M_Door material:

Changing the Sphere's material to "M_Door" in Unreal Engine

After that, Sphere should look like the door texture is stretched over it:

Texture applied to our Sphere in Unreal Engine

Then, in the Sphere’s Physics component, we’ll enable the Simulate Physics property. This way the Sphere object would be affected by the Physics system:

Physics component of the Sphere object in Unreal Engine

Let’s start the game now by pressing the Play button in the Main Toolbar above the Level Viewport:

Pressing the Play button in the Main Toolbar

Once the game starts, you’ll see the Sphere dropping to the floor. Also, the default camera actor in our level has physics enabled on it. So, when the game runs, you can move the Sphere by flying into it:

Physics being applied to our Sphere object in Unreal Engine

Multi-Object Physics Interactions

We can also combine those physics interactions with other objects. Let’s build a little ramp for our Sphere to run on. First, we will create a new Cube object through the Add > Shapes > Cube menu:

Adding a Cube object to the level in Unreal Engine

Then, in the Details panel we’ll configure the Cube’s Transform component like this:

  • Set the Location property to (0, 0, 70)
  • Set the Rotation property to (0, -20, 0)
  • Set the Scale property to (5, 1, 0.25)

Cube's Transform component in Unreal Engine

Next, let’s select the Sphere object, and in the Details panel, set the Transform’s Position property to (-150, 0, 270):

Setting up the Location of the Cube object in Unreal Engine

In the result, you should get the inclined rectangular ramp and the Sphere hanging over it:

Sphere hanging over an inclined ramp in Unreal Engine

If you start the game now, you should see the Sphere fall to the ramp and then roll from it to the ground:

Starting the game makes the Sphere roll down the ramp

Gravity Property

There are also other useful properties in the Physics component. For example, you can disable the Sphere’s gravity by disabling the Enable Gravity field. This way, the Sphere is still affected by physics, but not by gravity:

Enabling the Gravity property for the Sphere in Unreal Engine

If you start the game with the Sphere’s gravity disabled, the Sphere won’t fall to the ground by itself, but you would still be able to nudge the Sphere by flying into it:

Sphere does not fall down with Gravity property disabled in Unreal Engine

Let’s enable the Sphere’s gravity back now and look into other properties:

Enabling Gravity for the Sphere object in Unreal Engine

Linear and Angular Damping Properties

There are Linear and Angular Damping properties in the Physics component. They control how fast the linear and angular movement of the object is slowed down with time. By default, the Linear Damping should be 0.01 and the Angular Damping should be 0:

Linear and Angular Damping properties of the Sphere in Unreal Engine

If you start the game right now, without changing those parameters, the Sphere is going to roll until it falls from the Ground object:

Sphere relation to the Ground object in Unreal Engine

Let’s set the Angular Damping property to 5 and see how the Sphere rolls after that:

Setting up the "Angular Damping" property in Unreal Engine

When you start the game, the Sphere should stop almost right after it rolls from the ramp. That’s because now the Sphere’s Angular Damping is much higher:

Sphere now stopping right after rolling out of the ramp in Unreal Engine

Mass Property

The next property we’re interested in the Physics component is the Mass. By default, this property is disabled and the Mass is generated automatically by the engine depending on the object’s volume. For our Sphere object, the default Mass is around 109 kg:

Mass property in Unreal Engine

Now, let’s enable the Sphere’s Mass property and set it to 1, so our Sphere weighs 1 kg:

Enabling the Sphere's Mass property in Unreal Engine

If you start the game now, the Sphere will behave almost the same, but it would move further than before because it is lighter.

Conclusion

And that concludes our study of actors, lights, and physics in Unreal Engine! Well done on reaching the end of this tutorial!

With this tutorial, you’ve learned how to manipulate game objects/actors in various ways, including working with lights and physics in Unreal Engine. Foundations such as these form the core knowledge you’ll surely need to have a go at any sort of Unreal Engine game you want to build in the future!

Of course, Unreal Engine has a lot more tools to offer. We encourage you to not only explore other features of the engine, but to do further research into the aspects we covered here. There is a lot more to each – such as designing aspects for lighting or physics properties for different sorts of objects. Experiment, and maybe you’ll even generate the idea for your next Unreal Engine game!

Happy learning! (:

Want to learn more about features and tools in Unreal Engine? Try our complete Intro to Unreal Engine Game Development course.

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.

]]>
How to Set up Environments with QUIXEL in Unreal Engine https://gamedevacademy.org/unreal-quixel-tutorial/ Fri, 31 Mar 2023 01:00:34 +0000 https://gamedevacademy.org/?p=21708 Read more]]>

You can access the full course here: MAKE A PLANE ARCADE GAME IN UNREAL ENGINE

Environment – Part 1

In this lesson, we will learn how to set up our environment to create a more visually appealing game. By using Quixel Bridge, we can easily download high-quality photo-scanned assets for free. Quixel is basically a library of many different photo-scanned, 3D models that can be used for free within Unreal Engine.

Using Quixel Bridge

To get started with Quixel Bridge, go to Window and then Quixel Bridge. You can also undock the window for ease of use.

Quixel Bridge

Next press the Planet symbol and choose Environment.

Planet symbol and Environment

From here, Scroll Down and choose the Natural environment option.

Natural environment

This will give you many different environments to choose from, feel free to pick any environment you like, however in this course we will be using the Artic Ice And Snow environment collection.

Artic Ice And Snow

Now you can select an asset you like and click and drag it into your level, this will download and spawn the object in your level. It may prompt you to sign in before downloading in the bottom right.

asset

You can then move, rotate and scale your 3D model as you see fit within the level to build your scene.

You can also click and drag materials onto objects in your scene, to try this, select a ground material from Quixel Bridge and drag it onto our ground cube in the level.

materials

Now you can bring in any 3D models, materials, and props you like from Quixel Bridge to make your environment. Also, duplicate the rings we created previously to set up a course for your plane to fly through!

Environment – Part 2

In our example level we created a small, inclosed environment using the Quixel Bridge assets and made a large path of rings through out it for the player to fly through.

inclosed environment

Testing

We’re now ready to press Play to test out the game.

Testing

You should now be able to control your plane, fly through all of the rings and complete the course while increasing your score. You are now all set for creating your own arcade plane game, you could expand upon this in multiple ways such as adding weapons to shoot at targets with, a race objective around an obstacle course or adding collisions to the walls.

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.

Transcript – Environment – Part 1

Welcome back, everyone. In this lesson we are gonna be working on setting up our environment.

Now, right now you can see we have a pretty bland environment right here with just the rings, the floor, and the default sky.

So what we’re gonna do is we are gonna go ahead and use Quixel Bridge in order to get some high quality photo scanned assets into our game here. So to do this, we’re gonna go up to Window, we’re gonna go over to the Quixel Bridge.

Now, Quixel is basically a library of hundreds and thousands of different photo scanned 3D models. So these are high quality models that we can just drag and drop into our project for free, okay?

So in the bridge here, what we’re gonna do is I’m just gonna undock this window because we do sort of want it in the same view as our level here. And what we’re gonna do is we are just going to search for what we want.

So on the left hand side here, you’ll see there is a little planet. And I’m gonna hover over that, I’m gonna click on it, I mean, click on environment, and then environment here, we’re gonna go down click on natural.

And as you can see, there are plenty of different environments we can choose from. I’m gonna go Arctic Ice and Snow, just ’cause I think that’ll be pretty cool for a plane game.

And yet we can then go through, click on an asset that we might like, and you may have a option down here to log in before you actually download these.

And make sure you do that. Just log in with your Google account, with your Epic Games account. There’s plenty of ways to log in.

So once you do that, what we can do is we’re not gonna click on download because that will download it to our computer and makes it a bit hard to find.

Instead, what we’re gonna do is we are gonna click and drag on the thing that we want, and we’re gonna click and drag it into our level here. And then you’ll see that it spawns in like so, okay?

We can then scale it up, move it around, rotate it, and this basically just acts as a 3D model. And depending on which quality you set here, it depends on of course the size of the textures and the size of the model.

But overall, these models do look pretty good. And something else we can do is then, on our ground, we can click and drag on this material to apply it like so. And there we go.

We have that snow texture now applied to our ground. What I want you to do now is just go through and drag in the 3D models that you wish to create and set up your environment.

Okay, there are plenty of different models and environment set pieces here. So set those up. And also go ahead and start duplicating these rings and positioning them in places where, you know, you might have a nice challenging flight game to play. So I’ll be right back to see how you’re doing.

Transcript – Environment – Part 2

Okay, so you to go at that challenge. Pretty much just start placing those models around. As you can see, I also put these rings around, so the players to fly through them.

And you also got some other ground assets here to just add to the environment. So we can press play and test it out. Okay, increase our flight speed. Make it over to the ring little course I made over here. And there we go.

So as you can see, you can pretty much create whatever sort of flight arcade game you want. You might even wanna start adding in some weapons to the planes if you want.

You might add some targets that you could shoot down. Really, there’s a lot of things you can do with this little plane blueprint right here. You can of course, create rings like we’ve done. You can create weapons, create targets.

You might even wanna create a race around an obstacle course with collisions on the walls, so that if you were to bounce into them, the plane would explode. And yeah, that is our plane game inside of Unreal Engine.

Thank you for watching.

Interested in continuing?  Check out our all-access plan which includes 250+ courses, guided curriculums, new courses monthly, access to expert course mentors, and more!

]]>
Free Course – Create Interactable Objects in Unreal Engine https://gamedevacademy.org/unreal-interactable-tutorial/ Fri, 10 Feb 2023 01:00:00 +0000 https://gamedevacademy.org/?p=19826 Read more]]>

Master stories and simple game interactions in Unreal Engine by making a single system applicable to multiple objects. You can also extend the material covered here by checking out the full course below!

CREATE A WALKING SIMULATOR IN UNREAL ENGINE

About

In this free tutorial, instructor Daniel Buckley will walk you through the beginning steps of creating interactable objects in the popular Unreal Engine. Using the Blueprints Visual Scripting system, you’ll learn how to create and set up a player that detects interactable objects made with the blueprints class and a custom event that initiates interaction. Regardless of your game project pursuits, these skills for building interactable objects will provide you with new ways to express yourself creatively and add interactions via the Blueprints Visual Scripting system!

New to Unreal?  Consider downloading our free Unreal Engine 101 course!

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.

]]>
Unreal Engine Blueprints Tutorials – Complete Guide https://gamedevacademy.org/unreal-blueprints-tutorial/ Sun, 08 Jan 2023 01:00:07 +0000 https://gamedevacademy.org/?p=11952 Read more]]> For those who can’t or simply don’t want to learn how to program, visual scripting is a fantastic way to avoid it while still creating amazing games and apps.

In this article, we’re going to explore the best solution when it comes to game development of this kind: Unreal Engine’s Blueprints Visual Scripting system.

If you’re ready to explore no-code ways to make your dream games, let’s dig in.

Introduction to Unreal Engine

The Unreal Engine, is a game engine which is accessible to both triple-A game developers and beginners. When creating a complex and large scale game, you’d most likely use Unreal’s built in C++ support to have deep-rooted control over the engine’s systems. Although for a beginner, programming can be seen as a daunting task, especially if they also need to learn the engine. That’s where blueprints come in handy. Blueprints, is Unreal Engine’s visual scripting system.

BUILD YOUR OWN GAMES

Get 250+ coding courses for

$1

AVAILABLE FOR A LIMITED TIME ONLY

What is Visual Scripting?

Visual scripting is where you can create logic for your game (just like programming) but in a visual form. In Unreal, blueprints use nodes connected to each other. These nodes can be events (i.e. whenever you press the space bar), actions (i.e. move the player here), conditions (i.e. is this equal to this?), etc. Nodes can also have inputs and outputs. You give a node some input values, it will calculate what it needs then return some outputs for you to use.

Example of flow control with Unreal blueprints.

One import concept of blueprints is flow control. In programming, the code is read from the top down, computing everything along the way. It’s the same with blueprints, although we can guide the progression of flow. Nodes can have an input, output, or both for the flow to pass through. In the image below, you’ll see that we have a number of different nodes, connected by white lines. These white lines control the flow and tell the compiler which nodes to trigger next. Think of this as electricity, and the white lines are powering nodes along its path.

You’ll see that some nodes also have these colored connectors on the left/right. These are the input and output values. Nodes can take in data to use, such as with the DestroyActor node. This node takes in a Target and destroys that object. Some nodes also have both inputs and outputs. It takes in some values, uses those to calculate something, then outputs a result.

A number of nodes connected in Unreal Engine's blueprint system.

You can connect a large number of these nodes together, setup loops, functions, and events just like you would in a programming language.

Here’s another example blueprint. When we press the space bar (triggers the Space Bar node), we’re moving ourselves up in the air. Then the Delay node will hold the flow for 1 second and after that, move us back down.

Event Graph preview from Unreal Engine

There are many online resources to learn Unreal Engine and the blueprint system. With diverse documentation and video tutorials, Unreal sets up their developers with many avenues to learn the engine.

Blueprints vs Programming

In Unreal, we have the choice between using blueprints and C++ programming, but which should you use? When starting out with the engine, using blueprints can be a great way of getting into game development without needing to learn programming. Although if you ever wish to create a more complex/large scale game or intend to work in the industry, learning to program may be the next step.

If there’s something you want to create in Unreal, then most likely it can be done using blueprints. Player controllers, AI enemies, cars, etc. The blueprint system is quite powerful and boasts a large number of nodes for you to use. What you can create is only limited by what you don’t know, so I recommend you just play around with the engine and try creating some blueprints of your own. A great way to get started would be to look at the template projects that come with Unreal. There are a number of different games, each with their own systems – all created with blueprints!

Links

Tutorials

Hopefully these links help you get on track with your Unreal Engine projects. However, if it’s your first time diving into game development, we recommend checking out our tutorial on making a game in general.

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.

]]>
Learn Unit Movement for RTS Games with Unreal Engine https://gamedevacademy.org/unreal-rts-movement-tutorial/ Fri, 06 Jan 2023 01:00:38 +0000 https://gamedevacademy.org/?p=19599 Read more]]>

You can access the full course here: BUILD AN RTS GAME WITH UNREAL ENGINE

Unit Movement – Part 1

In this lesson, we will start creating our Units.

Creating The Unit Blueprint

First of all, let’s create the Unit blueprint:

  • Go to the Content folder in the Content Browser
  • Create a new Blueprint Class in the Content folder
  • Select the Character as the Parent Class for that blueprint
  • Name that blueprint Unit

This Unit blueprint will be used as the base for both the Player and Enemy Units.

Player and Enemy Units

Next, let’s add some visuals to our Unit:

  • Open the Unit blueprint by double-clicking on it
  • Drag the Bishop model from the Content > Models folder to the Unit component in the Components panel

Components panel

Now our Unit has the Bishop model.

Bishop model

Then, let’s drag the Bishop model down so it fits nicely into the Capsule Collider our Unit has.

Capsule Collider

Or you can just set the Bishop’s Location in the Details panel to (0, 0, -88).

Location Details panel

Next, we’ll give our bishop the Unit_1 material in the Details > Material dropdown.

Material dropdown

This will make our Bishop blue.

Bishop blue

Setting Up The Unit’s Target Position

Now, let’s go to the Unit’s Event Graph tab. This is where we will create all of the logic for moving, attacking, and taking damage.

Event Graph

First of all, we need to create a variable to store the target movement position:

  • Go to the Variables dropdown in the My Blueprint panel
  • Create a new variable called TargetPosition

variable TargetPosition

Then, let’s change the type of the TargetPosition variable to the Vector:

  • Go to the Details panel
  • Set the Variable Type property to the Vector type
  • Compile the blueprint so those changes would be applied to the blueprint

Vector type

By default, the TargetPosition is (0, 0, 0), which means, our Units will go to the (0, 0, 0) position at the start of the game. As we don’t want this to happen, we will initialize the TargetPosition variable with the Unit’s position instead:

  • In the EventGraph, connect the BeginPlay event node to a new Set Target Position node
  • Connect the Set Target Position node’s Target Position pin to a new Get Nav Agent Location node

This way, we will get the Unit’s start position from the Nav Mesh and set it to the TargetPosition variable.

Unit start position

Moving To The Target Position

Next, we want to move our Unit towards the TargetPosition:

  • Connect the Tick event node control flow pin to a new AI MoveTo node. This node uses the Nav Mesh to move Actors
  • Connect the Pawn pin of the MoveTo node to a new Self node. This way, we’re telling the MoveTo node to move the Actor which calls it
  • Connect the Destination pin of the MoveTo node to a new Get Target Position node, so this node will know where to move our Unit
  • Compile the Unit blueprint so the changes would take place

Compile Unit blueprint

Let’s go back to the GameLevel level, add the Unit to the level, and start the game to see what happens.

GameLevel level

The only thing which should actually happen is the Unit Actor positioning itself to be on the Ground. As we set the TargetPosition to the Unit’s position at the start of the game and haven’t implemented any input, our Unit has no reason to move now.

Actor positioning

Just to test the Nav Mesh, let’s disconnect the BeginPlay node from the Set node in the Unit’s Event Graph. This way, the Target Position would have the default (0, 0, 0) value at the start of the game.

Unit Event Graph

If you start the game now, you should see the Unit go to the (0, 0, 0) location. The Unit will even go around the obstacles we set earlier.

start game

Unit location obstacles

You may think that our Unit moves too fast. Let’s change the Unit’s speed now:

  • Open the Unit blueprint
  • In the Components panel, select the Character Movement component
  • In the Details panel, in the Character Movement: Walking dropdown set the Max Walk Speed property to 300

Max Walk Speed property

If you start the game now, you should notice that our Unit moves slower. You can test out different speeds and pick the one you like.

Don’t forget to reconnect the BeginPlay event node to the Set node before going to the next lesson.

reconnect BeginPlay event node

In this lesson, we created the Unit blueprint and made it go to the Target Position using the Nav Mesh. In the next lesson, we’ll add input handling, so we would be able to actually tell our Unit where to go.

Unit Movement – Part 2

In this lesson, we will make our Units moveable by Player.

Creating The Player Unit

First of all, let’s remove the Unit Actor from the level. Only the Cube obstacles and Nav Mesh should remain.

remove Unit Actor

We’re not actually going to use the Unit blueprint instances in the level. Instead, we will use it as the base for the Player and Enemy Unit blueprints.

Let’s create the PlayerUnit blueprint now:

  • Create a new Blueprint Class in the Content folder
  • In the Pick Parent Class window, go to the All Classes dropdown
  • In that dropdown, find and select the Unit class, to use the Unit as the parent class
  • Click on the Select button to create that blueprint
  • Name that blueprint PlayerUnit

Blueprint Class

blueprint PlayerUnit

If you open PlayerUnit’s Event Graph, you will see that its event nodes are connected to the Parent event nodes. The Parent event nodes are the ones we’ve defined in the Unit’s Event Graph. This means, PlayerUnit’s Event Graph runs the code defined in its parent – the Unit blueprint.

Event Graph

Selecting The Player Unit

Now, let’s implement the Unit selection with our Player Controller:

  • Open the RTSPlayerController blueprint
  • Go to the Event Graph tab
  • In the My Blueprint panel, add a new variable called SelectedUnit.

Blueprint panel

Next, in the Details panel, we’ll set the SelectedUnit’s Variable Type property to the Player Unit.

Details panel Variable Type

As we want to select our Units with our mouse, let’s enable the Mouse Cursor first:

  • Connect the BeginPlay event to a new Set Show Mouse Cursor node
  • Enable the Show Mouse Cursor property in that Set node

Show Mouse Cursor node

Then, we’ll add the Left Mouse Button event node, to get notified on when the left mouse button is pressed.

Left Mouse Button event node

Next, we will send a raycast to check if there is any object under our cursor:

  • Add a new Get Hit Result Under Cursor by Channel node to the Event Graph
  • Connect the Hit Result pin of that node to a new Break Hit Result node

The Get Hit Result Under Cursor node sends the raycast from the cursor position and returns the result of that raycast. A raycast shoots through space like a laser beam and returns the objects which got in its way.

Get Hit Result Under Cursor by Channel

Then, we will check if we hit the Player Unit Actor:

  • Expand the Break Hit Result node to see all of its output pins
  • Connect the Hit Actor pin of the Break Hit Result node to a new Cast To PlayerUnit node
  • You can collapse the Break Hit Result node now, as the used pins will remain visible

Now we have the Cast To PlayerUnit node which can tell us if we hit the PlayerUnit Actor by passing the control flow to its first pin.

Cast To PlayerUnit node

Finally, we can set the Selected Unit variable:

  • Connect the Pressed pin of the Left Mouse Button node to the input control flow pin of the Cast To PlayerUnit node
  • Connect the first output control flow pin of the Cast To PlayerUnit node to a new Set Selected Unit node
  • Connect the As Player Unit pin of the Cast To PlayerUnit node to the Selected Unit pin of that new Set node

Now, once we press the left mouse button, we check the object under our cursor, and if it happens to be the Player Unit, we’re saving it in the Selected Unit variable.

Selected Unit variable

Setting Up The Player Unit Movement

Next, we’ll make the Units move with the right mouse button click. Let’s add the Right Mouse Button event node to the Event Graph first.

Right Mouse Button event node

Then, let’s copy the raycast nodes we created earlier:

  • Select the Get Hit Result Under Cursor by Channel and Break Hit Result nodes we created earlier
  • Press Ctrl+C to copy and Ctrl+V to paste those nodes
  • Move the copy of those nodes to be below the RightMouseButton event node
  • The connection between those nodes must remain

copy raycast nodes

We also need to check if we actually have a Unit selected:

  • Connect the Pressed pin of the Right Mouse Button node to a new Is Valid node
  • Connect the Input Object pin of the Is Valid node to a new Get Selected Unit node

This way, on the right mouse button click, we’ll check if we selected a Unit first.

Is Valid node

Creating The Unit’s MoveTo Function

Then, we need to return back to the Unit blueprint to set up a way to set the Target Position variable from outside. We will make changes to the base Unit blueprint, as both the Player and Enemy Units will need to get their Target Positions from outside.

Let’s do the following now:

  • Open the Unit’s Event Graph
  • In the My Blueprint panel add a new function called MoveTo

MoveTo function

Next, in the MoveTo function Details panel, add a new input of the Vector type called ToPosition.

Vector type ToPosition

Finally, let’s make the Move To function set the TargetPosition variable:

  • In the Move To function graph, connect the control flow pin of the Move To node to a new Set Target Position node
  • Connect the To Position pin of the Move To node to the Target Position pin of the Set node
  • Compile the Unit blueprint to apply those changes

Now we can set the Unit’s Target Position with the Move To function.

Unit Target Position

Back To The Player Controller

Let’s return to the Event Graph of the RTSPlayerController blueprint now. We can finally connect the script we started earlier to the Unit’s MoveTo function:

  • Connect the Get Selected Unit node to a new Move To node. You need to make that connection first, as only the node of the Unit type can be connected to the Unit’s Move To function Target pin
  • Connect the Is Valid pin of the Is Valid node to the input control flow pin of the Move To node
  • Connect the Impact Point pin of the Break Hit Result node to the To Position pin of the Move To node

Now, when we click the right mouse button and we have a PlayerUnit selected, we will call the MoveTo function on it with the click position as the target position.

Player Controller

Testing The Movement

Let’s get back to the GameLevel level and test how our new input works. First, let’s add two PlayerUnits to the level to make sure that our selection works as it should.

Testing Movement

If you start the game now, you should be able to select a PlayerUnit by clicking it with the left mouse button and move it by clicking the right mouse button somewhere on the Ground. Though the selection itself is not displayed at the moment, we will work on it in one of the following lessons.

start game

In this lesson, we implemented the ability to move the PlayerUnits. In the next lesson, we will start working on the Combat system.

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.

Transcript – Unit Movement – Part 1

Welcome back everyone in this lesson we are gonna begin creating our units.

So first of all, we want to go down to our content draw and we wanna go to our content folder where we have our level and our other blueprints that have already been created.

And what we want to do is right-click go blueprint class and we want to select the character blueprint. Okay. And I am gonna call this one Unit.

Now this is gonna be the base blueprint for all of our different units, both the player and the enemy. And then from here what we’re gonna do is we are gonna extend from that for the player units and extend for that for the enemy unit.

Okay. So if you do want certain logics such as AI for our enemies cause our enemies are going to be able to attack on their own when a player gets within range but we don’t want our players to do that.

So we are going to basically have a separate player and a separate enemy blueprint. Okay. But this unit blueprint is basically going to be the parent class for both of those.

So all of the similar logics, such as being able to move to a location, move to a target is gonna be shared between them inside of this blueprint here. And we’re getting better understanding of how that works later on.

Once we start setting up the others, but for now let’s just open up this unit blueprint by double-clicking on it and we can then dock it like so. just to make it a bit neater.

Now, the first thing we want to do is give ourselves a 3-D model because right now we have no visual. So what I’m gonna do is I’m gonna open up the content draw.

I’m gonna go to our models folder and I’m just gonna drag in the Bishop 3-D model under the unit here, we can select that model.

And what we want to do is we basically wanna drag it down so that it is sitting at the bottom of this capsule right here. And this capsule is basically defining the bounds of our unit. Now let’s actually disable the grid snapping here so we can move it up a tiny bit, just so it fits correctly. There we go.

And let’s also give it a material now to give it a material we can go over to our details panel, go down to the materials and let’s give this one unit I’ll give it ‘unit_1’, which is just a blue one like so. And then we go, so that is our 3-D model. Pretty much all set up.

Now what we need to do is go over to the event graph where we are going to be spending most of our time, setting up the various different pieces of logic for our unit.

Now inside of this unit blueprint, we are gonna be making a bunch of different things. First of all, we’re gonna have it so that this unit can move to a target. It can also move to a position in the world.

For example, when we right-click on the ground our player’s gonna move to that position. When we right-click on an enemy, we want it to move and attack that enemy.

We’re also gonna have logic that works for attacking a target when we get within range and also for taking damage. So let’s start simple and just get our unit moving.

So first things first, we need to create a variable here which is actually going to determine the position we want to move to. So I’m gonna create a new variable down here.

I’m gonna call this one target position over in the details panel. We can change the variable type from a boolean over to a vector, which has an X, Y and Z coordinate that we are going to move towards.

We can click compile to save all those changes. And then over inside of begin play. What we want to do is initially we want to set our target position to be our current location. And that is because we don’t want our target.

We don’t want our unit I mean to start moving over to 0, 0, 0 at the start of the game, we want them to stand still. So we’re gonna set their target position to basically be their existing one.

So from begin play I’m gonna drag out and go set target position. And the target position is basically just going to be Get Nav Agent Location. Okay. So that’s gonna get the location of our AI agent.

And an agent is basically an entity that utilizes a nav mesh. So it’s basically gonna get our current location on the nav mesh. Now the active begin overlap node which detects collisions. We don’t really need that.

So we can actually go ahead and delete it like so. but the event tick we definitely will need. Now with event tick what we want to do is we basically want to be moving towards our target position at all times for now though. Okay.

So I’m gonna do is I’m gonna drag out from event tick here with the control and I’m gonna drag this into a node called AI move to, okay this one right here, AI move to, and this node right here basically we give it some information and it is gonna automatically calculate a path and move us towards our target location.

So what information do we need to give it give? Well, first of all, we need to give it the pawn or the object that we want to move, which is gonna be ourself.

So we can just right-click and look for the self node right here, get a reference to self and drag that into the pawn. Now we also need a destination and of course that destination is gonna be our target position.

So we can drag in target position, go get target position and connect that up like so. Okay. And pretty much that is all we need to do.

So now if we compile this, if we go back to our game level we can actually go to our content draw, go back to content drag in a unit here, there we go. They’re on the ground.

And if we press play, you’ll see that nothing happens because we initially set their target position to be their existing one. But what happens if we don’t do that? What if we go to unit? What if we right-click on the begin play node and just go over to where it says break node links.

That will disconnect it. If we click compile, if we go back to game level and we move our player over here, for example and we press play.

What you’ll see is our character now moves over or it’s trying to move over to the (0,0) coordinate which is pretty much inside of this cube right here. okay. So we can move it over, down below here.

So there is an obstacle in the way, and as you can see it moves around this obstacle towards the target. Now you may think it is moving a bit fast and it kind of is.

So what we can do is go over to our unit here and select our character movement component. And what we want to do here is just change the move speed. So if we go down to where it says, max walk speed.

We can change that to let’s just say 300. So now if we compile that, go to our game level, press play you’ll see that we move at a much slower speed and we can see the AI navigation a bit easier. But yeah, that is basically how we can navigate around obstacles using the AI move to node.

Now I’m gonna reconnect the begin play to that set target position because we do want to actually have our target position set to wherever we are right now by default.

And in the next lesson we are going to be looking at making it so that we can actually tell our player where to move. Okay.

We’re gonna be able to select our player with left mouse and right-click on the ground to move to a position. okay. So we’re gonna get that RTS movement and interaction set up. So Thank you for watching! and I’ll see all then in the next lesson.

Transcript – Unit Movement – Part 2

Welcome back, everyone. In this lesson, we are gonna get our player controller set up and working so we can actually start selecting our units and moving them around.

And we are first of all going to actually create another unit blueprint. And that is going to be our player unit. Because this unit right here, this unit blueprint, we aren’t going to ever be using it.

So, let’s go ahead and delete our unit that exists in our world right now, because we’re never gonna drag this unit blueprint into our world.

Rather, we are gonna create two other blueprints, a player unit, and an enemy blueprint. And those are both going to inherit, or they’re both gonna be a child class of this unit blueprint.

So it’s basically, we want the enemy and the player to both have the same characteristics and the same logic as each other, but they’re gonna differ in certain ways that we do want to give themselves different behaviors, such as the enemy is gonna have automatic AI, and the player is going to have the ability to be selected.

So, I’m gonna right-click. I’m gonna create a new blueprint class. And we need to pick a parent class. Now, we wanna go All Classes, because we want to search for our unit right here.

And this unit is gonna be our parent class. And I’m gonna call this one PlayerUnit. Now what happens, if I open this up, you’ll see that we have the player bishop right here. We have everything set up just as it is over in Unit.

Yet, if we go to Event Graph, you’ll see that our BeginPlay connects to this thing called Parent BeginPlay. And Parent BeginPlay is basically what this code here, or this logic over in Unit, that we are setting up here.

Because everything inside of PlayerUnit is sort of overriding or inheriting from Unit. That stuff already exists. And any changes we make to the Unit blueprint, those changes get applied to our PlayerUnit as well.

And then what we can do is just attach on extra logic, extra gameplay behaviors, to our player unit here that are more player-centric. And if we create the enemy blueprint, that’s gonna be more enemy-centric with the AI.

And of course we’ll get into this a bit later on on the specifics, but for now just know that PlayerUnit is basically inheriting everything from this unit blueprint right here, with the ability to add on its own extra unique properties.

So, now what we want to do is open up our RTSPlayerController blueprint right here. And this is going to be where we are detecting all of our mouse clicks, and keeping track of which units we have currently selected.

So inside of the player controller, what we want to do is go over to our Event Graph here, and we want to create ourselves a new variable. And this variable is going to be called SelectedUnit.

And the variable type is not gonna be boolean or vector, rather it is gonna be of type player unit. Like so. We can compile that to save those settings.

And now what we need to do is we need a way of basically determining when we click on a player unit. So, first things first, in BeginPlay, we’re going to connect this over into a Show Mouse Cursor node and enable that, because we do want our mouse cursor enabled by default.

We then want to delete Event Tick, since we won’t be needing that. And instead we want to create a Left Mouse Button node. And this Left Mouse Button node is gonna basically execute once the left mouse button is pressed or released.

Now, what we want to do is we want to basically determine if we are clicking on a player unit when we select it with the left mouse buttons. How do we do that? Well, we need to use a raycast, or a hit result.

So, for this what I’m gonna do is I’m gonna create a node called Get Hit Results Under Cursor by Channel. And this node right here, basically, it is going to shoot a laser beam from my mouse cursor to whatever we are pointing.

And it is then gonna return to us that information whenever it hits something. Now from Hit Result, we wanna bring this over into a Break Hit Result node right here.

You can then pop that open to see all of the different outputs we can choose from. Now, the thing we ought to check to see is the Hit Actor. And we to know if whatever actor we hit with our mouse cursor is a player unit.

So, we can drag that out like so. And we are going to put this into a Cast to Player Unit node. Now, a Cast To node, it basically takes in an object as an input, and it basically determines if this object is of type player unit.

If it is, this Control Flow executes. Otherwise, Cast Failed executes. So, basically this is only going to be true if the object we are clicking on is a player unit. So, let’s connect this up with the pressed input like so.

And then from Cast, if it is indeed a player unit, then what we want to do is we want to basically go Set Selected Unit, and go As Player Unit. And like so. So, now when we left-click on a player unit, it is going to set it as our selected unit.

Now, how do we get that unit to actually begin moving around once we have it selected? Well, for that, we are gonna create another event node called Right Mouse Button.

And Right Mouse Button, this gets executed when, of course, we click on our right mouse button. And what we want to do with this is we basically to start off with, want to see, first of all, do we have a selected unit?

And if we do have a selected unit, then we want to move it to whatever location we have hit. So, what we can do here is actually just to save some typing,

I’m gonna select our Get Hit Result under cursor, hold down Control, and select the other node here. I’m gonna copy that and paste it down here, just ’cause we don’t have to worry about creating those nodes again.

And instead of the Hit Actor, we want to get the Location. But we don’t wanna get that just yet. Instead, what we want to do is we want to go out from Pressed, and we want to check to see if we have a selected unit.

Because we don’t wanna try and move somewhere if we don’t have a selected unit. So out from Pressed, what we want to do is we want to check to see the Is Valid. Is Valid right here, a little question mark icon.

Basically, we give it a object and it determines if it exists or not. So, right now our selected unit if we get it like so, plug it in. If it has not been set, it is equal to what’s known as null.

Null basically means empty. And if it’s empty, that means it is not valid. Otherwise, if we have set the selected unit, it will be valid. Now, if it is valid, then we want to basically set its target position.

And to do that, we are gonna go over to our PlayerUnit right here. And actually not our PlayerUnit. We’re gonna go over to our Unit, so our base unit, because this could also be given to an enemy.

And we are going to create a new function down here called MoveTo. And the MoveTo function is going to contain a input. So, we can add an input right here. And it is gonna be called ToPosition. We wanna make that of type vector.

And basically what we want to do is set our target position to be this ToPosition. So, we just wanna plug it in like so and there we go. So, basically when this Move To function is called, we send over a position and it is gonna set our unit’s target position.

Now we wanna click Compile, go back to our RTSPlayerController. And then what we want to do is we want to drag in our selected unit here, go Get Selected Unit, drag that out, and we want to call the Move To function like so.

And we wanna connect that to the Is Valid of the Is Valid node. And the ToPosition is going to be the Impact Point, the point at which our mouse cursor has impacted, probably the ground that we wanna move to.

So, that is what we need to do in order to basically set it up for our unit to be selected initially. And then when we right-click, we want to check to see if we have a unit selected.

And if we do, we want to move it to wherever our mouse cursor has clicked on the ground. So, now we can click Compile. We can go back to our game level. We can then drag in a player unit here.

Let’s actually drag in another one as well just to basically see if the selecting works. Click Play. Okay, and now what we can do is we can click on our unit.

So, if I click on the left one right here, nothing really happens so far, but we will have a selection visual appear. And if I right-click, you’ll see that our unit is now moving to whatever position I am giving it, which is pretty cool.

Now, if I select this other unit with left mouse, as you can see, I am now controlling it, and the other one is staying still.

So, we can switch between our units here and move them around wherever we wish by clicking on them and then right-clicking on the ground to basically navigate over to that location.

So, that’s all working nicely right there. All right, so we got that all set up and ready to go. Now in the next lesson, I reckon we look at setting up some sort of enemy.

Because we need a way to actually begin attacking other units, and then later on, them having the ability to attack us. So, thanks for watching. And I’ll see you all then in the next lesson.

Interested in continuing?  Check out our all-access plan which includes 250+ courses, guided curriculums, new courses monthly, access to expert course mentors, and more!

]]>
How to Create a NAV MESH with Unreal Engine https://gamedevacademy.org/unreal-nav-mesh-tutorial/ Fri, 23 Dec 2022 01:00:24 +0000 https://gamedevacademy.org/?p=19377 Read more]]>

You can access the full course here: BUILD AN RTS GAME WITH UNREAL ENGINE

Nav Mesh

In this lesson, we will set up the Navigation Mesh for our project.

Creating The Obstacles

The Nav Mesh system allows Actors to navigate in the level. In this game, we won’t control the units’ movement directly. We will point to a place where units should go and then they will use the Nav Mesh to navigate the level. The Nav Mesh will also help our units go around obstacles instead of going through them.

Speaking of obstacles, let’s add a couple of cubes to the level. To add a cube to the level, select the Add > Shapes > Cube option from the main toolbar.

Shapes cube

A new Cube Actor will appear in the level.

Cube Actor

Let’s duplicate this cube now:

  • Make sure the Cube Actor is selected in the Outliner panel. You can select an Actor by clicking on it either in the Outliner or in the Level Viewport
  • Press the Ctrl+D hotkey to create a copy of this Cube Actor. Create as many copies as you want
  • Drag those Cubes to different positions on the level

Now we have the Cube obstacles in our level.

Cube obstacles

Setting Up The Navigation Mesh

Next, let’s go and select the Add > Volumes > NavMeshBoundsVolume option from the main toolbar to create a new Nav Mesh Actor.

Nav Mesh Actor

The NavMeshBoundsVolume Actor looks like a cube without visuals – only edges are visible. The NavMeshBoundsVolume Actor defines a volume, for which the Navigation Mesh will be generated.

Navigation Mesh

Now we need to configure the NavMeshBoundsVolume. First, let’s go to the Details panel and set the Transform > Location property to (0, 0, 0), so our Nav Mesh would be positioned in the center of the level.

Transform Location property

Then, we will make this Nav Mesh big enough to fit our level. Let’s go to the Brush Settings dropdown in the Details panel and set the (X, Y, Z) properties to (8000, 8000, 600).

Brush settings

This way, the Nav Mesh should be big enough to fit the Ground Actor inside.

Ground Actor

But how do we check that the Nav Mesh works? You should just press the P key to enable the navigation preview in the Level View. The walkable part of the level would be highlighted in green. The ground around cubes won’t be highlighted in green, which means this ground is un-walkable.

Level View

In this lesson, we added some obstacles to our level and added the Nav Mesh Actor to help our units to navigate around those obstacles. In the next lesson, we will start working on the units which can walk in our level.

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.

Transcript

Welcome back everyone. In this lesson, we are gonna be setting up our nav mesh and our AI navigation for our project.

Because, since we are using units that we aren’t directly controlling with an input, so we’re not really telling them to move left, right, or whatever. Instead, we are telling our units to move to a specific location.

And if there is an obstacle in the way, such as a box or a big rock, we want our units to move around it, rather than trying to go directly through the center. So how do we do that?

Well, first of all, let’s go ahead and just add in some obstacles. So I’m just gonna go up to here, where we can add in some objects.

And I’m gonna add in, let’s just say a cube, okay? You can bring that down like so, maybe increase it in scale a bit. And I am just going to move a cube here.

Duplicate with Ctrl D and just place a couple of them down here, just so we have an understanding of what this nav mesh does.

Okay, so we have our cubes placed down. Now, let’s just say we have a unit that is behind this one right here, and we want it to move on the other side.

Now, typically when you’d move a blueprint, or move a character, you just basically tell it to move in the direction that you want it to.

Yet, we can’t do that, because there is an obstacle in the way right here. And we have to create what’s known as a nav mesh, which is basically an asset that determines all of the walkable space in our level.

So how do we do that? Well, let’s go up to this little dropdown here, where we can create objects. And actually instead, we’re not gonna go here.

We are gonna open up the Place Actors menu, or the Place Actors panel. And if you don’t have that, you can just go window, Place Actors right here.

Now, in Place Actors, what we want to do is, we want to look for nav. And you should see here that we have ourself a Nav Mesh Bounds Volume. And we want to drag that into our project here. Okay?

Now you’ll see that this is sort of like a cube, but without the visual. And this is because, the Nav Mesh Bounds Volume basically defines an area of which it will generate a nav mesh for.

So what we need to do is, go to our details panel. I’m gonna set the location to be zero on the X, zero on the Y, zero on the Z. So you can see it’s pretty much in the center of our world right here.

And we need to basically increase the size of this selected box here. So to do that, we can scroll down in the details panel, and we want to go down to the brush settings, okay?

And you see here, we have the X, Y, and Z values. Basically, we just want to… When I increase these, we can basically change how big this is going to be, okay?

So just make sure that the bounds of this box here fit our level, because only the objects within this selected boundary are going to be calculated for a nav mesh.

Now, we’ve got that here, but how do we know it’s working? Well, what you can do is, press the P key on your keyboard. And you should see now that we have the walkable ground selected, okay?

So you can see here, around our cubes, we have this sort of like a gap, like it’s being cut out. And that basically means that our cubes are defined as non walkable.

If something wants to walk through a cube, it is gonna calculate a path going around it, okay?

So basically, whenever we want to move from one spot to another, it is only going to be moving on this sort of selected green plain here.

So great! That is how we can set up a nav mesh bounds volume. Now in the next lesson, we are gonna be looking at creating a unit which can actually utilize this, and move from one spot to another using AI.

So, thanks for watching. And I’ll see you all then in the next lesson.

Interested in continuing?  Check out our all-access plan which includes 250+ courses, guided curriculums, new courses monthly, access to expert course mentors, and more!

]]>
Unity vs. Unreal – Choosing a Game Engine https://gamedevacademy.org/unity-vs-unreal/ Mon, 19 Dec 2022 03:51:08 +0000 https://gamedevacademy.org/?p=12773 Read more]]> When learning game development, people often wonder about what the best game engine is – in fact, we’ve done a whole entire article on the matter. In terms of versatility, power, popularity, and use in the industry – there are two that most people talk about though: the Unity game engine and the Unreal Engine.

Answering which one is better is a difficult matter. Some will argue Unreal is better simply for the fact it is a top choice for AAA studios. Others, however, will cite the fact that Unity is more well-rounded and, for indie developers, is often a better entry into the industry. Objectively, though, is one better than the other?

In this article, we’ll be going over the pros and cons for each engine and have a true battle of Unity vs. Unreal. We will also help you get started with learning both so no matter your ultimate decision, you can jump into creating your own games right away. Let’s get started, and hopefully by the end, you will be able to make an informed choice about which game engine is the engine of your dreams.

BUILD YOUR OWN GAMES

Get 250+ coding courses for

$1

AVAILABLE FOR A LIMITED TIME ONLY

Versatility

As a game developer, you might want to experiment with different types of games – 3D, 2D, multiplayer, VR, AR, etc. Having an engine that caters to a wide range of games is important and luckily, both Unity and Unreal do just that. Let’s have a look at a range of different game types and which engine would be best suited for them:

  • 3D – Both engines have great 3D capabilities, although Unreal is best in terms of graphical fidelity.
  • 2D – Both engines can do 2D, although Unity has a much larger focus and tool-set.
  • Virtual Reality – Unity excels in VR as the plugins are very versatile and integrate into the overall XR infrastructure.
  • Augmented Reality – Both engines can do AR, although Unity has been doing it for longer and has much more defined systems.
  • Multiplayer – Both engines can do multiplayer, although Unreal is the only one with integrated support. Unity’s integrated multiplayer is still in-development although there are many 3rd-party frameworks.
  • Mobile – Unity is considered the best engine for mobile.

Creating a 2D game in the Unity engine.
Creating a 2D game in the Unity engine.

Creating a 3D game in the Unreal Engine.
Creating a 3D game in the Unreal Engine.

Coding

When starting out with a game engine, what language you code in can be a determining factor. In Unity, you write code using the C# language, while in Unreal you use C++. Generally, C++ is considered a more difficult language to learn, although Unreal has its own integrated visual scripter called Blueprints. Visual scripting is a great alternative to coding as it allows you to do the same things – yet with no coding required. Just create nodes and connect them together in order to develop logic for your game.

While both engines have visual scripting, Unreal Engine’s Blueprints Visual Scripting system has existed longer, and is a more established way of “coding” for the engine. Though recent versions of Unity have added visual scripting as an option, the standard way of scripting behaviors is still considered to be C# programming.

Unreal Engine Blueprint visual scripting.
Blueprints in the Unreal Engine.

All in all, if you are looking to code, Unity may be the easier option with C#. Although, if you don’t want to code, you can use Unreal’s Blueprints.

Industry Presence

You may choose a game engine based on what the professionals are using. Both Unity and Unreal are used to create games on the market, but in different ways.

First, Unity is the most popular engine for indie developers and mobile games. There are a number of larger games made with Unity such as: Hearthstone, Cities: Skylines, Rust, Ori and the Blind Forest, and most mobile games.

In terms of the AAA-industry, Unreal is used more than Unity. Games such as: Fortnite, Bioshock, Sea of Thieves, Star Wars: Jedi Fallen Order, and a large number of others use the engine.

Something to also keep in mind is how the engine developers themselves use it. Unity don’t create their own games apart from small educational projects. Epic Games (developers of the Unreal Engine) on the other hand, have developed many games such as: Fortnite and Gears of War using the Unreal Engine.

Worldwide global forecast for the games market

Community

An important aspect of a game engine is the community. Both engines have a pretty large online presence, with their own respective forums, Sub-Reddits, YouTube channels and more.

  • Unity – has a yearly game developer convention called Unite. Most game development YouTubers focus on using and teaching Unity.
  • Unreal – Epic Games has more of a presence online with live tutorials.

Both engines also have their respective asset stores. An asset store is a marketplace for 3D models, textures, systems, etc for an engine which you can get for free or a price. These can be great for developers who may not be the best artist or lack knowledge in a certain area.

Several programmers working as a team

Tutorials

Both Unity and Unreal have great learning resources. Documentation, tutorials, online courses, etc. Below we’ve listed a number of different courses on Unity and Unreal.

Unity

Unreal

Robot hand playing Go

Conclusion

We’ve let our battle of Unity vs. Unreal play out, but let’s turn back to our original question: which engine should you use?

Ultimately, this will depend on you and your needs. However, if we might be so bold, we can at least say the following:

  • If you’re a beginner looking to learn how to code and create a wide range of games – go with Unity.
  • If you’re not interested in coding and want better graphical performance – go with Unreal.

Overall, these are still quite surface-level statements, so we recommend you try both before making any decision. However, as you try these engines out, you can keep the information here in mind, as there are things to consider you can’t learn by doing! Even so, remember there’s no best game engine – there’s only the game engine you feel most comfortable using. Whether you pick Unity or whether you pick Unreal Engine, the world is at your fingertips. So get out there, and create some amazing games and apps!

BUILD GAMES

FINAL DAYS: Unlock 250+ coding courses, guided learning paths, help from expert mentors, and more.

]]>