Wednesday, December 24, 2014

functions and UFUNCTIONS

Functions can exist in two basic forms: a regular C++ function or a UFunction.  Both C++ functions and UFunctions are declared in the .h class header file.

UFunctions use a specialized syntax that allows additional information about the function to be specified in the declaration through the use of Function Specifiers.


C++ functions are declared using the standard C++ syntax for declaring a function. 


UFunctions behave the same as C++ functions in that they have a C++ implementation, can be called from within C++ code, and can contain calls to other C++ functions or UFunctions within their function bodies.  UFunctions differ in a few areas, however.  For instance, they can be called or overridden from within the Blueprint Visual Scripting system.  Any UFunction declared using the BlueprintCallable, BlueprintImplementableEvent, or BlueprintPure specifiers will be exposed to Blueprints. 


UFunctions are also used as replication callbacks; meaning the UFunction will be called when the variable it is associated with changes and is replicated across the network. 


*UFunctions can also be assigned as delegates within the default properties of a class.  This technique is commonly used to bind input actions to functions in Input classes. 

*UFunctions are also the only type of function that can be declared as an exec function allowing them to be called by the player from the in-game console during play.

Monday, December 22, 2014

Initialization and Post Initialization

Since our last tutorial I have added a few more 'UPROPERTY'.  The these will help with creating the functionality we are looking for.  In this tutorial lets look at initializing the grenade as well as adding a post initialization component.



When we initialize any class in the unreal engine we want to setup the 'CollisionComp', 'MovementComp' and other useful information like does this actor tick or not?



CollisionComp defines how the class will interact with the game world.  The most important functions of the collision component are 'InitSphereRadius' and 'SetCollisionResponseToChannel'.

The 'InitSphereRadius' creates a capsule around the class which handles all the collision.  Without this there would be no collision for the class.  Creating a collision capsule also improves performance since it simplifies collision detection.  

The 'SetCollisionResponseToChannel' allows you to define how this class will interact with other objects.  For example you could set 
CollisionComp->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Ignore);
This will allow the class to travel through walls and other static meshes.  As you can image you can get create with all the different collision response channels.

MovementComp defines all the aspects of the classes movement.  There are many cool functions that allow you to set things such as: InitialSpeed, MaxSpeed, ProjectileGravityScale, etc.


Lastly 'Tick' is a function that will run 'x' milliseconds.  Tick offers a lot of cool potential.  For example if you wanted to add a 'Damage Over Time' effect for player characters you could add something like the following:
if (IsPoisoned == true)
{
Health -= 10.0f;
}

In the above example, for every second 'IsPoisoned ' is true, the player will take 10 damage to his/her health.

'PostInitializeComponents' is a function that runs once the class is spawned in game.  In our example of the grenade, that would be once the player presses the key to start to throw a grenade.  Then we are going to do three things in our 'PostInitializeComponents'.



First we are going to set the life span of the grenade.  This is going to be when the grenade explodes and is then subsequently removed from the game.  We set the life span to 4 seconds, which is standard for a grenade's life.

Next we are going to tell the grenade who created him.  This will be useful for obtaining statistical information, like whose grenade killed the enemy.  We could also do interesting things like player perks that increase the damage of grenades.

UPROPERTY

I wanna talk about the 'UPROPERTY' this is one of the most fundamental features of coding with UE4. Before we start with that, lets discuss what we did in the last tutorial. If you take a look at 'ArenaFragGrenade.h' we can see some basics of defining a class in UE4. Every class is proceeded with the declaration of 'UCLASS()'. This simply tell the engine that this code is to be appear in the editor as a class. This means that from here on out you can create objects of this class inside the editor. Also you can inherit from this class as well. Inside that declaration we added a few tags 'Abstract' and 'Blueprintable'.

Abstract declares the class as an "abstract base class", preventing the user from adding Actors of this class to the world in Unreal Editor or creating instances of this class during the game.

Blueprintable allows this class to be added onto or modified in the Unreal Editor through the use of blueprints.  This makes working and tweaking the class much easier.

GENERATE_BODY() must be the first thing inside any class header.


What we are talking about today is the 'UPROPERTY'.  Prefacing a variable with 'UPROPERTY' tells the Unreal Engine that you want it to know about this variable.  Inside a 'UPROPERTY' are tags that further define how you want the engine to handle this variable.  Lets create a variable for the explosion visual, we'll call it 'ExplosionTemplate'.  In our example we have the 'EditDefaultsOnly' and 'Category = Effects' tags in the 'UPROPERTY'.  

EditDefaultsOnly tells the Unreal Editor that only the default value for this variable can be changed in the editor.  This means that this variable cannot be changed during gameplay.  

Category = Effects helps us organize the 'UPROPERTY'.  We told the Unreal Editor to put this variable under the 'Effects' category.  We could have set the category to anything we wanted.  If the category didn't previously exist then it would create it.  If the category already existed then it would simply add this variable to the other in the category.

*Notice that I added a new class called 'ArenaExplosionEffect'.  I quickly created this class for the purpose of this tutorial.  We will cover it more in a future tutorial but basically it is a classes that defines how the particle FX of the explosion will look.  I just wanted to point that out in case it confuses anyone.  Lets build the code!


Now that we have compiled the code and are in the editor, lets create a grenade blueprint.  Navigate to the 'Blueprints' folder and open the 'Weapons' folder.  This will be a good place to put our grenade blueprint.  We will then right-click on any blank space in the content browser.  Then, from the pop-up menu click 'Blueprint' which will start a setup wizard.


All blueprints need to inherit from code.  When it asks us for a parent class we are going to look for our 'ArenaFragGrenage'.  We can simply type the name into the search bar to find it easily.  Once you have located it, click it and then click 'Select'.


It will give our new blueprint a default name.  Lets right-click on it and select rename and call it 'Arena_FGrenage' this will help us to identify it in the future.  If we double-click on it, it will open up the blueprint.


With the blueprint open we can navigate to the 'Defaults' tab.  If you recall these are the values we are able to edit with the 'EditDefaultsOnly' tag.  At the top we see a category called 'Effects' with a variable called 'Explosion Template'.  


Here we can find our 'Arena_FExplosion' blueprint (that I previously created for this demo) and assign it to this variable.  This will tell our grenade class to how to look when it explodes.  There are still a couple steps missing in order to get the grenade actually working.  In the next few tutorials we will learn how to interact with a 'UPROPERTY' and how it greatly simplifies the code.  Click 'Compile' and then 'Save'.


Saturday, December 20, 2014

Adding Code to Project

The next few post will be all connected.  We will be adding the ability to throw a grenade in game.  So for the next few post we will be going step by step on how to implement this new feature.  Each post will cover a different concept.  Lets start by talking about how to add code to a project.

To add a new .cpp file or .h file is a little different from normal coding practice.  Since there are a lot of external dependencies that are going on behind the scenes there is a specific way to add new code to a project.  First we want to compile and build the game.


Next we want to go to 'File'.


Go down to 'Add Code to Project'.


We then want to check the box 'Show All Classes' in order to see all the classes for inheritance.


Now that we can see all the classes.  We want to select 'Actor' as the parent class.  We are picking Actor because there is nothing similar to a grenade to inherit from.  'Actor' is like the base parent for anything that exists in game.   


Next we want to preserve the existing file structure to maintain organization of the code.  So we are going to click 'Choose Folder'.


We are going to place the grenade in the 'Weapons' folder.


We need to remember to name the grenade class.  We are going to name it 'ArenaFragGrenade'.  The naming nomenclature we are using is to preface all classes with the word 'Arena'.  



Now we are going to click 'Create Class'.  The prompt is going to ask if we would like to edit the code now.  We are going to click 'Yes'.


Visual Studios is going to ask to reload the project.  Go ahead and click 'Reload All'.


Then Visual Studios is going to ask you to stop debugging.  Just click 'Yes'.


We are all done now!  We have successfully added new code to the project.


If you notice at the top of the 'ArenaFragGrenade.h' there is an include for  'ArenaFragGrenade.generated.h'.  This is an auto generated header that includes all the necessary external dependencies the code needs to properly interact with the Unreal Engine.  We never need to touch that file.   

Getting Started

1.  The first thing we need to do is insure we have a code editor that we can work with.  Unreal Engine 4 is only available for Mac and PC.  If running Windows I suggest using Visual Studios.  It is free for students, all you need to have is an email address with '.edu' at the end.  Follow the link below to get Visual Studios for free: 

https://www.dreamspark.com/Product/Product.aspx?productid=93

If you are using a Mac, XCode also works.  However, note that XCode user are required to have a signing ID which requires you to have a developer account with Apple.  I believe a developer account is a yearly fee and as far as I know, there is no way around it.

2.  Next we need to download the 'Unreal Engine 4'.  Simply follow the link below:

https://www.unrealengine.com/dashboard

After following the link you will be brought to this page:


If you are part of 'TheArena' development team.  The sign-in credentials are posted on the Podio homepage.  After you sign in you will see the following page:


On the left side of the page there are two links to download the engine.  One for Windows and one for Macs.  Download the appropriate file.  After the file has downloaded, proceed to install the engine on your computer by selecting a location to install it and clicking 'Install'.



Once the engine has been successfully installed you will see the following page.  Enter in the log in credentials from the Podio page and hit enter.


Once signed in, you will be presented with the license agreement for the Unreal Engine 4.  Read the agreement and then click 'Agree'.



Next navigate to the 'Library' section of the launcher.



Insure you have version 4.6.1 selected.  The click 'Install' and wait for it to finish.

.

4. Finally we are want to clone 'TheArena' GitHub repository to your local machine.  If you do not have git installed on your computer, follow the appropriate link below:

Windows: https://windows.github.com/
Mac: https://mac.github.com/

Once you have finished downloading the file, double click it to begin the installation.  Click 'Install'


It may take a couple minutes to complete the installation. 


When it is finished installing it will probably automatically open this view.  If you have been added to 'TheArena' repository then you can click the '+' in the top left, select 'Clone' and find 'TheArena' and clone it.



If you have yet to be added as a collaborator to 'TheArena' you can still clone the repository.  Simply close the above application and find and run 'Git Shell' application (Git Shell is installed with the GitHub GUI).



Next to clone repository, copy and paste the following line into the terminal then hit 'Enter'.  (To paste, simply right click).
git clone https://github.com/Jeff-Stapleton/TheArena.git

Once the files have been successfully cloned, its time to run it!  Open 'File Explorer' and navigate to where you cloned the files.


At this point I recommend making a copying all the files to another folder.  I recommend working on the copied version.  This will make your life easier once you finish a specific feature and want to upload it to GitHub.  You will have to merge your version with the master version.  I will create a tutorial on merging later to explain in more detail.  Once you have made you copy to work on open it up.  Right click on 'TheArena.uproject' file.


When you right click on the 'TheArena.uproject' file you will see the following drop down menu.  Find and click on the option 'Generate Visual Studio project files'.  For Mac users, this will be hidden under the 'properties' section of the drop down.


This will create a solutions file.  Double click the solutions file and it will launch your code editor. 


Now you can begin to program or run the existing code. 


After clicking run, it will build and launch the game in the Unreal Editor.  Here you will be able to test the game!



Thanks for viewing my tutorial.  I will be adding more regularly that will go into details about coding, content designing and testing.










Saturday, December 13, 2014

The Arena: Documented!

Supposedly there is going to be a video game symposium in February at BYU.  There are going to be a lot of big name companies there such as Epic Games and  Disney Interactive.  Part of the symposium is about students who are currently developing games.  I thought that this could be a good chance to meet some influential people and make our presence known.  As part of the application I made a quick 2 minute video showing what has been implemented so far.  Enjoy!


Wednesday, December 3, 2014

UI

I feel UI has the biggest impact on immersion than any other element.  I hate bad a UI and I love a good UI.  So what makes a UI bad or good?  First lets talk about bad UIs.

Bad UI clutters the screen with ugly windows.  They distract from the game play rather than enhance and enrich it.  Bad UI requires the player to come out of the game experience in order to check inventory, viewing maps, or changing spells/abilities.

A good UI tries to maintain the realism and immersion of the game.  It tries to integrate the concepts of inventory, maps and abilities into the experience.  Tom Clancys: The Division is a game that is doing a fantastic good job of this.  All the UI elements you see make sense, they add to the game rather than distract.