Unreal Engine 4

 Table of contents:

Oculus Rift and GUI

During my bachelor work, I wrote about GUI creation with the Oculus Rift and Unity 3D. Since I am now more experienced with Unreal Engine 4 I thought I’ll give GUI creation with Oculus Rift DK1 and Unreal Engine 4 a try.
Here is a little sneak peak:


I have done this simple showcase with the help of a Oculus Rift template for Unreal Engine 4, so I don’t have to worry about setting up the Oculus Rift functionality (e.g. Head movement). Therefore I could focus on actual features. Within six hours I managed to get those two types of GUIs working and I was impressed how well 3D widgets in Unreal Engine are working, even though they are still in an experimental state in Unreal Engine 4.9.

CastHitOnWidget - Here I check if I look at a widget. Then I call the "Activate" Event.

CastHitOnWidget – Here I check if I look at a widget. Then I call the „Activate“ Event.

Unreal Engnie 4 GUI & Oculus Rift Showcase_Event Graph

Event Graph of Widget – Here you can see the activation event which then allows the widget to start rotating and moving in the correct position.

Unreal Engnie 4 GUI & Oculus Rift Showcase_RotateWidget

Rotate Widget – This is the function I use to rotate the widget in move it towards the designated position.

Unreal Engnie 4 GUI & Oculus Rift Showcase_ExampleBinding

This is an example binding I use inside my widget to change the color of the progress bars.

Please keep in mind, that unlike the following content, the functions and bindings above are not refactored or optimized.

 

A Prototype with Blueprints

Since I graduated from SAE Institute Hamburg, I started to work with Unreal Engine 4. I decided to develop a little prototype in the survival genre. I chose this genre, be cause I would have lots of possibilities for different game mechanics. My personal goal for this project is to create a prototype that fulfills one complete user story. In this case the player should be able to survive. The player is able to hunt down a animal and get food. Then he can gather some wood from trees and create a fireplace through a crafting menu. Finally he can cook the food and eat it. This is shown in the following clip:

Currently there are two other team mates working on this project (One programmer and one artist). As you can see in the video most of the object are block outs. Also the „animal“ is just the standard unreal character.

Finally I would like to show you some of the blueprints I created for this prototype. The first function („Update Ingredients Text“), I would like to show you, displays which ingredients are used for a specific recipe and shows if the player has any of the necessary items. This function relies on a second function, which actually checks if the player has those items („Check if Ingredients Available“).

Project_365_GUI_CraftingMenu_UpdateIngredients

Update Ingredients Text – Forward recipe to second function („Check if Ingredients Available“) and check returned bool condition.

Project_365_GUI_CraftingMenu_UpdateIngredients2

Update Ingredients Text – Whether the player can craft or not, we now have to find out how many items the player actually has. First step: Does the player have at least one of the specified ingredient?

Each item has its own recipes stored in a custom structure. This way I can store all the necessary ingredients for each recipe. The function „Check if Ingredients Available“ returns a structure that contains all ingredients inside the players inventory. Therefore I can now use this data to adjust the user interface.

Project_365_GUI_CraftingMenu_UpdateIngredients3

Update Ingredients Text – Now I need to compare the classes to find the appropriate match. On one side I take the class stored in the recipe and on the other side I take the class from the ingredient in the players inventory. If I found the correct match I stop the for each loop.

Project_365_GUI_CraftingMenu_UpdateIngredients4

Update Ingredients Text – Next I take the bool condition stored in the custom structure, to check if the player has enough of the ingredient. Either way I will now take the display name from the ingredient (also stored in the item itself) and combine that text with the amount and the amount I need for that recipe.

Project_365_GUI_CraftingMenu_UpdateIngredients5

Update Ingredients Text – Depending on the bool condition ( Bool variable „Enough for recipe“) I will now make the text inside the crafting menu appear green or red.

Project_365_GUI_CraftingMenu_UpdateIngredients6

Update Ingredients Text – In case the player does not have any ingredient, we will again make the text appear red, but this time I need to get the class from the recipe instead of the item inside the players inventory, since the item does not exist.

Now lets take a look at the second function „Check if Ingredients Available“.

Project_365_Character_Crafting_CheckIfIngredientsAvailable

Check if Ingredients Available – First of all we take the recipe and loop through each ingredient. Then we check if the ingredient is present.

Project_365_Character_Crafting_CheckIfIngredientsAvailable2

Check if Ingredients Available – In case it is not present, we will create a sort of fake reference inside the „Ingredients“ Array. We need to do this, as you have seen before, we still need to know about the ingredient even if it is not present inside the players inventory. Also we set the can craft bool to false.

Project_365_Character_Crafting_CheckIfIngredientsAvailable3

Check if Ingredients Available – In case the player does not have the ingredient the function is pretty much done. But if the player has the ingredient with at least one amount, the function will then go inside the for each loop with break. Inside this loop we need to go through all items in my inventory which are the ingredient type. Now we need to check the amount. If it is greater or equal the amount from the recipe we can set „Can Craft“ to true and add a reference to the „Ingredients“ array and stop thee for each loop since we found what we need. Otherwise the for each loop would until its done.

Project_365_Character_Crafting_CheckIfIngredientsAvailable4

Check if Ingredients Available – Here you can see the function returns the „Ingredients“ array and the bool „Can Craft“, which will be used in the function „Update Ingredients Text“.

Last but not least I would like to show a very simple binding I use to update the output amount for each recipe. These bindings find their use in my project very often when I comes to update some kind of information for the GUI.

Project_365_GUI_CraftingMenu_Get_TB_OutputAmount

Get TB Output Amount Text – This binding find the output amount out of a specific recipe and returns that value.

Since the whole project is made with blueprints I am now working on a C++ implementation. At the beginning of my project I decided to make everything in blueprints, be cause I was able to get quick results. Furthermore it was much easier to learn how the engine works and to get a basic understanding.

C++ Actor Utilities Class

I have finished my first C++ class for Unreal Engine 4 and would like to show you some of it. Here is the .h file for the class definitions:UE4_ActorUtilities_H

This is a very simple class for now and only has too generic function I use a few times in my blueprints to either get a location in front of an actor or the get the closest overlapping actor.

Here is the .cpp file:

Function – GetLocationInFrontofObject

UE4_ActorUtilities_GetLocationInFrontOfObject

GetLocationInFrontOfObject – This function is used to return a location in front of an actor. This is mainly used for dropping or spawning any items (e.g. Wood planks ).

Function – GetClosestOverlappingActor

UE4_ActorUtilities_GetClosestOverlappingActor

GetClosestOverlappingActor – This function is used to return exactly one actor out of many. Let’s say we have five items laying on the ground waiting to picked up. I use this function to determine which item is the closest one to the character. Then I can show an interaction text specifically for that item and the item can be picked up.

Since both function are supposed to be used inside blueprints, here is how it looks like in a blueprint: UE4_ActorUtilities_BP