Unreal Engine — Some Basic Tools

This is part 2 of an ongoing student learning blog. (Part 1)

Unreal provides tools for all your jobs

In this blog I will covering materials, mesh colliders and components. These three topics provide the basis for visuals, physics and game logic. After exploring these you will begin to see how quickly you can start to make a simple game.


In the simplest terms materials are you ‘paint’ they take basic shapes and objects bring character and color to them. However unlike your home depot paint they also define other visual aspects of an object such as texture, reflectivity and transparency. Materials are what take a basic sphere polygon and turn it into a basketball that a player can recognize. They are the basics for all visuals in Unreal Engine.

Rock mesh with basic material

What we are looking at above is a rock mesh included in the unreal starter content. A mesh is what gives something its shape. Now with a basic material it is pretty hard to tell what we are trying to place it is just a mashup of polygons. We will put the proper material back onto the mesh and with unreal it is as easy as dragging your material and dropping it on the mesh.

Rock mesh with rock material

Now what we have is much more rocky. The detail a material can provide is huge and really tells the story of your objects. It turns a pile of white playdough into a moss covered rock. Now our rock may look great but currently they only thing you can do with this rock is look at it. We need to add a collider to make this rock ‘real’.


Spooky

As you can see here if we just place an object in the game world with no collider we pass threw it as if we were a ghost. However by default our player has a collider so it is actually the rock that isn’t part of the physical world. We need to edit the mesh so it has a collider attached to it.

The Static Mesh Editor

Unreal provides a handy tool called the static mesh editor. This gives us all the things we can add to our mesh, but right now we are just worried about collision. The light blue lines across the rock indicate the shape of the rock already provided by the creator of the mesh. The green box around it is the box collider that I added. Now you may be wondering why our collider box is square and not the shape of the rock. That is because complex colliders are hard to process and to much detail would be overkill for a simple object like this. However, when it just comes to moving around an object the player will not be able to tell the difference.

Success!

Now our rock is part of our physical plane. Now that we have objects we can interact with we want them to be able to do things besides just sit there like rocks. By attaching components to our objects we can really bring our game to life.


You could call components the brains of our objects how ever in a lot of cases they are going to be more like simple machinery that gives certain outputs. Components are scripts that can manipulate objects, the player and even the game world. They provide a simple way of controlling objects and creating the rules of our games. So let’s make our rock move!

Click an object and simple click to add a new component.

You can create components using C++ or with Blueprints. Blueprints are basically building blocks that even non programmers can use to design the logic of their games. In this case i’m going to use C++ to move my rock.

After Clicking ‘New C++ Component’ it will ask you what type of component you want to make. Unreal Refers to all game objects as ‘Actors’ so we will select the Actor component. Unreal will by default open the Windows Visual Studio Project that was generated when you start a new Unreal Project.

Now this isn’t a C++ or an object oriented coding tutorial so forgive me if you get lost.

What unreal generates for you is a new SubClass of the ActorComponent Class in the Unreal library. This class provides methods to manipulate your objects directly and the unreal library provides everything you need to change anything via code.

When you check out the code you will see Unreal has generated three functions for you. The two that you add your code to to manipulate objects are called BeginPlay and TickComponent. The BeginPlay function will run your code when your game starts up while your TickComponent function will run itself every frame(Game time unit).

Inherited Functions of AActor

It is in the TickComponent fuction that we are going to add code to make our rock fly.

Code to make our rock fly

Here is a quick high level breakdown of what we are doing

  1. GetOwner(); We are getting the Actor(Or Object) that this component is attached to.
  2. Owner->GetActorLocation(); We are getting an object that contains the X,Y,Z values which Unreal uses to calculate Locations of things.
  3. Location.Z += 1; Increment the Z axis by 1.
  4. Owner->SetActorLocation(Location); Replace the old location of the object with the new one.

Now since this is code is written inside the TickComponent function it is going to run every frame, which is very frequent, this will result in our rock constantly ascending upwards until the game has been stopped. Click the compile button in the unreal editor to apply the changes to your game.

Now before the code is run the Rock has to be set to movable or the code will not do anything! This can be done easily in the Unreal Editor.

Set to movable

Here we go!

We have lift off!

Now this example may seem silly or useless, but understanding how to manipulate your game is the key that unlocks the power of a game engine.


I hope you enjoyed this demo of unreal next time I hope to talk about Triggers that can be activated by players that can be used to run code after certain events allowing players to interact with the world in new ways.

Thanks for reading!