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.   

No comments :

Post a Comment