Introduction to Programming | Live Training | Unreal Engine

Introduction to Programming | Live Training | Unreal Engine

Unreal Engine 4 Tutorial
Intro to Programming   Hello and welcome. This video is going to be an
introduction to Unreal Engine 4 code, sort of a crash course for coding,
if you will. We’re going to go through the
process of starting a new project. We’ll implement a simple feature,
and maybe show a few interesting other things along the way. I’m going to assume that you have installed
Visual Studio, or Xcode beforehand, that you’ve downloaded the Unreal
Engine 4 source from GitHub, followed all of the directions there,
and managed to successfully build the engine once. I’m also going to show everything
on a pc, but, if you’re on a mac, you should be able to
follow along just fine as well. If you do want to follow along,
and you haven’t done these steps, now would be a good time
to pause and go do that. If not, let’s get going! First thing I want to show
is… You already did this if you’ve built, but we have this
“GenerateProjectFiles” batch file. This batch file will do what it says;
it will generate the project files for you. So, this is handy to run from time to time
if you’re manually adding or removing source code files from your project. It’s not required to compile or run
or anything like that, but it will make your life
a little bit easier sometimes to have those files
show up in your IDE. So, if you want to get them in your IDE,
that’s a nice way to do that.   Also, and this is going to be more
of interest to Visual Studio users, we have a couple of things
to make your lives easier. One is this UE4.natvis file. You can install it with this
batch file right here. This will customize the display of some
of our Unreal specific common types in the debugger to make them
easier to use. So you don’t have to go digging
through in your watch windows to find the values that
you’re interested in. So, I highly recommend
installing that. If you are a full version of
Visual Studio 2013 user, this won’t work for Express,
but this UnrealVS plugin will give you a little toolbar,
which is handy for a couple common workflows
in Unreal. So, I would definitely recommend
installing that as well. And it has been… And I’ll show this to you
in a couple of minutes… Crap. So, let’s find our solution
file and open it up. Okay. A couple things I want to point out
here real fast… This drop-down right here is the
Platform drop-down. We’ll stick with Win64 for now, but, if you’re going to build
for another platform, that would be the place
where you would choose that. Here in the Solution Configuration
drop-downs, typically you’re going to want to build
one of these editor configurations, because it builds in the editor
and it’s pretty useful to have the editor for
developing your product. So, the big difference between, Debug,
DebugGame, and Development here is you’re going to be choosing a trade-off
between run-time speed and debug ability, with development being
the most highly optimized but the least debugable
and debug being the least optimized
but most easily debugable. I tend to stay in debug
as much as possible, because I like being able
to step through my code in trust with what the
debugger’s telling me. If you’re spending a lot of time
working exclusively in your game code, and you’re not stepping down
into the engine very often, the DebugGame configuration is
very useful for those scenarios. It’ll optimize all of the engine modules, but it will leave your game modules
in debug mode, so you can debug what
you want to debug and still get some good performance. Also, I want to show,
this toolbar right here, is the UnrealVS toolbar,
which I mentioned earlier. So we have two key
drop-downs here. This first one is the Project,
the StarterProject. It’s really a shortcut for
picking a project out of here and saying, “Set as StartUp Project” So, instead of having the code
dig through this panel over here, you can just kind of get a little
short drop down for what you want. And this one right here
is the command-line drop-down; it comes with a little history
built into it. And that’s really a shortcut for
opening up your project settings and saying,
“Here’s my Command-Line Arguments” You can do a lot with Command-Line
Arguments in Unreal, and it’s a very nice way to quickly set
what you want to set without having to dig through
a bunch of menus. Okay, so, let’s run our editor and I’ll show you how to set up
a new project. Okay, so, since we didn’t select
any project, we’re just kind of running
the raw engine here. So it’s going to ask us if we
want to open or create a new project. If you had some projects,
you would see this, and you can pick a project
you’ve already made. But, since we don’t have one,
let’s make a new one. So here… Let’s… If you want to start completely clean,
you can click Blank, or Basic Code, and that basically gives you a
completely clean slate to deal with. We also have several, several templates
down here you can choose from. Which are nice elevators if you want to,
just, you kind of know, vaguely what you want
and want something to play with. So let’s make a side scroller. I’m going to leave this box
here checked, because I want to copy starter content
into it, into the new project. So, this way, we have some toys
in our toy box that we can play with. It’s about lunch time, so let’s make this project about Pizza,
because Pizza is delicious. So, we’re going to go ahead
and create that.   And you can see it’s copying
in the starter content. It’s going to go ahead and, basically, fully set up our project
in a compilable state for us. Here it is opened up,
into VisualStudio for us, and we should be ready to go. So, you can see, we still have
our engine code in our solution. Here’s our Pizza game code. You can see what it gave us. It gave us a couple of files here. So, like, this is our precompiled header. This is the module and the implementation. It’s given us code
for our basic character, so we’ll have somebody that we can,
so there’s a guy that can run around. And it also gave us the implementation
of a customized game mode, and a game mode is typically
a set of rules that defines your game. In this case, it just tells us to,
you know… Let’s use one of our Pizza
characters it made for us. So, let’s go ahead and build this
and see what it did for us.   I’m actually going to stop this,
because I changed my mind. Let’s set this to debug editor
so we can use our debugger. And also, I forgot to set this,
so this is important. We want to actually build
our Pizza project, and you can see it altered the
command line for us to load that up by default. So now let’s build it.   Okay, so now we have our
editor loaded up, and you can see we’re
editing our Pizza project. If this is your first time in the editor,
just a quick tour here. So, over here, is our content browser. This is where all the content
in the game is accessible. As you can see, we have quite a
bit of stuff in here, and this is our starter content
that we copied in. This over here is the Scene Outliner. In the 3D window, you can navigate around
and click on things and select them, or you can select them
through the Scene Outliner. It’s a nice quick way if you don’t want to try
and pixel hunt sometimes. You’ll notice that,
if you have something selected, it shows up here in the Details panel with a lot of information about it
that you can edit, or see. One nice thing, when you’re using code builds
is you’ll notice this link up here. This will take us to the class definition
of the object that you have selected. So, in this case,
I have selected the PlayerStart.h, and I can click on the
PlayerStart page. and here I’m on the PlayerStart.h, and I can look and read the comments
and see what properties there are. That can be a potentially useful feature for quickly navigating
between the editor and the code. Let’s just go back to the editor
real fast. Also, I want to show this feature
up here that we call play in editor. So, you can click on play
and actually play your game, and play your level,
right here in the viewport. So, as you can see, we have,
you know, it’s a side scroller. You can run around , you can jump,
and you can jump again.. So, you know, about
what you’d expect. So, let’s make this a
little more interesting. Let’s… We called it Pizza, so let’s
make a powerup in our game here, like a pizza powerup
that we can pick up. Because collecting little floating
things is a side scroller staple. So, first thing’s first,
we need to add a code module, or code class for our power up. So, let’s make a base powerup class, and we’ll go ahead and customize
that once we get in the editor. So, here in the file menu,
we have this option to add code to project. This is a nice quick way to handle
a lot of the Unreal specific boilerplate. So, I click on that, and I can
choose my parent class. And we have here a list of
commonly used parent classes. If you want to see them all,
click on this and you get the full tree
of parentable classes. But, really what we want
is something fairly simple, and we’re going to choose “Actor” Because an actor is our most basic
thing that exists in the world. Let’s go ahead and pick actor,
and click next, and we’re going to call this a Powerup. So, this will just be the base
class for all of our powerups. And it’s going to update
our solution file, and our projects, and copy in the code files for us…
and it’s done. So, yes, we want to edit it. I’m going to go ahead and reload
our environment and stop debugging. So, as you can see,
we now have two new files -our powerup header and our
powerup implementation file. It’s given us the class definition here,
and we’re ready to go. So, just sort of a quick tour around
in Unreal class, if you will, I’ll check out one of these. As you can see,
if you recall back to Unreal Engine 3, either we had a special language
for defining classes and for scripting, and, in Unreal Engine 4,
we’re using straight, native C++. Simply decorating the properties,
and classes, and structures, and functions, that we think are interesting and that we want the
Unreal object system to know about. So, in this case, our
Pizza character is a U class. This side view, camera component,
is a U property, which means it’ll show up in the editor
and you’ll get lots of other benefits.   Let’s go back to our
Powerup class. So, thinking about how our powerup
should behave, we want our little guy to run across,
and touch it, and pick it up, right? So, we need something
that we can touch. Let’s keep this simple. We’re going to have a property
for a sphere. So, this is going to be our
touch sphere. It’s a sphere component. I’ve tagged this U property
so that we can see it in the editor and we can edit its properties
if we need to. Now that we have this variable, let’s go ahead and create it
in our constructor. So, you can see, we’ve made it
into our constructor already. And.. I’ll just gonna..
paste it in…okay. So, you can see our touch sphere. We are going to create it. It is a sphere component. This is the owner of the…
who owns the sub objects. So, that would be us, the powerup
is going to own its own sub object. We’re going to set its radius to 20;
by default, that’s 20 centimeters. We’re going to set it
as the root component, which means it’s the… if you think of an actor as like a.. as being able to contain a hierarchy
of physical components, little blocks you can assemble You know, this one’s going to be root, so anything else we want to attach
to this we can hang off of this sphere. But this will be the base of the
hierarchy. So, to make it interesting, let’s also have our powerup
rotate to make it animated a little bit. So, let’s give it a rotation rate, and I’m going to make this a U property
also, so it’s editable in the editor. This will be in degrees per second. Let’s go ahead and initialize that
in our constructor as well. So, we’ll have it spin
at 180 degrees per second. In order to actually do the updating,
let’s override the actor’s tick function – this is the function that will
get called every frame. and.. We can…
implement it thusly. So, you can see, what we’re
doing here is, in our tick function… First order of business, we’re gonna go ahead and
just call our super class’s tick, so we don’t want to miss anything
important that it might be doing. Then, in our code, we’re going to get our
current rotation into an F rotator. An F rotator is an Unreal structure that contains the Euler angles
of orientation, so its pitch, yaw, and roll. And we’re going to take its roll, and we’re going to increment it
by the amount of rotation we have done this frame. And then go ahead and
just set it back to ourselves. We’re going to set
our own rotation to the new, newly updated rotation. One more thing we need to do
is that actor’s do not tick by default, for efficiency reasons. So, we need to tell it
that it is allowed to tick, like so. So, can it tick is true. Looks good. Let’s go ahead and build this,
and see what we’ve done. Okay, we’re back in the editor. So, we’ve made our
base class power up, but now we will make a
specific powerup. So, we’re going to use the
Blueprint system for this. A Blueprint,
or a class blueprint in this case, is essentially an editor defined
sub-class of a native class or of
another blueprint class. So, you can actually extend code
using only the editor. So, let’s go ahead and demonstrate this. I’ll go ahead and make one,
and we’ll call it, let’s see… New blueprint…you can
pick your parent class. Since we want to make it a powerup, we’re going to come down here
to custom classses and then look for powerup.
There it is. And now we have our blueprint. So, let’s name it, PizzaPowerUp. Okay, and we’ll go ahead
and edit that. Okay, just sort of a quick tour around
the blueprint interface here… A couple different parts of a blueprint… You can think of this as sort of a
visual representation of a code class. It’s the same concept. We have a bunch of defaults,
and these are the default values for the, you know, PizzaPowerUp,
almost like a constructor, if you will. You can see the one
we just added, RotationRate is here, and a bunch of other things
you can set. So, these are the default properties
of a PizzaPowerUp in your world. The graph is where
behavior code would go. You can set a…
to respond to events every tick. We could have done our rotation
here, if we wanted to, but we didn’t. And here in the components,
we can sort of… before, I was talking about
the hierarchy of components, here we can sort of assemble
that hierarchy visually, instead of typing coordinates
and stuff and offsets in code. So, this is a really nice way to
visually construct our actors. So, you can see, we created our
touch sphere in code, and here it is at the
root of our hierarchy. So, let’s give this a mesh,
so we have something that we can see. I know in the shapes here we have
a wedge shape, which is vaguely pizza-like. So, let’s go ahead and add
a static mesh component to this under the touch sphere, so it will be attached
to the touch sphere. Now, that looks awful big for pizza,
maybe it’s a deep dish, but I like New York style pizza. So let’s go ahead
and scale this guy a little bit. There we go. Now I’m going to rotate him
so he kind of faces the camera by default. That looks vaguely pizza shaped. A little grey, but can’t be picky. Okay. In the graph, let’s go ahead
and give it a simple behavior. So, let’s say, when we touch it,
we want it to just disappear just for now. Just to test that it’s working. We’re going to use
our overlap functionality. So, if any actor overlaps this actor, which means overlaps
the sphere in this case… So, when this happens, we will go ahead
and just destroy the actor. Just hit destroy. If you wanted to do anything interesting, like increase health or something,
this would be a great place to do it. But we’ll keep it simple for right now. One more thing I want to do… Let’s go back to the components here. I’m going to turn off collision
on the static mesh, because it’s on by default. It’s really just there to look pretty, since we’re actually going to
interact with the sphere. So, let’s go ahead and turn that off,
because I don’t want to get stuck on it. I’ll close this guy and go ahead
and play and see what happens. Well, nothing happens,
because I didn’t put one down. We’ll go back to the blueprints
real quick. Let’s put one of these in the world. That would help, so we can see it. Okay, that looks pretty good. All right. Now, we’ll play. There it is! Look, it’s rotating, and if I walk over and touch it,
it goes away. Beautiful! First try.
Well, second try. One thing I don’t like here
is this is rotating… I wasn’t really anticipating
it to rotate like this. I wanted it to rotate like this, which is not easy to describe
with my mouse cursor. Let’s try and change
the axis rotation on this, to make it match with
what I had in my head. So, let’s go back to the
code real quick, and you can see that
we were rotating about the roll. Let’s change that to
the yaw axis. So, go ahead and save that,
and go back…the code. So, this is a great opportunity
to demonstrate our compile, reload, and compiling feature. So, now that I’ve changed my code,
I can come up here to Compile and say,
“Recompile the game code” It will kick off a compile
of the game library, and reload it when it’s finished,
assuming there were no compile errors. This is a great feature for being able to make
little tweaks to the code without having to completely
bring down and restart the editor. It doesn’t work in all cases, like if you add new properties
to a new class or change your U class constructors,
or something like that It doesn’t handle those cases, but, if you’re just making
tweaks to your code, like you messed up your
matrix math or something like that… Quick iterations… this is a wonderful feature for quickly turning those
kinds of things around. Okay.
So, our compile’s finished. Let’s go ahead and hit play
and see what happens. And there it is! It’s rotating about the
yaw axis now instead of the roll axis,
just like we wanted. Or just like I wanted, at least. I can still touch it,
and it still works. Excellent.
Ship it. Alright. If you want to find out more
about coding in Unreal, I highly recommend checking out
some of the docs on the website and some of the other videos. There’s a lot more information
about the object model and different data structures
that come with Unreal. Thanks for watching,
and have fun!  

100 thoughts to “Introduction to Programming | Live Training | Unreal Engine”

  1. I was getting all pissed off and stuff because Visual studio was giving me a bunch of errors (mostly about intellisense) and I couldn't see my class in the editor, but today I though i'd give it another try and it just decided to work, including the intellisense in visual studio.

  2. you mentioned a file for visual express users to make life easier installed with a batch file couldnt understand you on the video bad aduio what was it

  3. Im looking to get into Unreal Engine 4 ( i haven't used any other game engine apart from Unity consistently). Can someone recommend a few good C++ books relating to game programming for UE4? Wanted to know a good place to start 

  4. Anyone getting build errors? I have a few popping out….

    Error 1 error C1083: Cannot open include file: 'atlbase.h': No such file or directory D:Program FilesGitHubUnrealEngineEngineSourceDeveloperWindowsVSAccessorPrivateVSAccessorModule.cpp 19 1 UE4
    Error 2 error : Failed to produce item: D:Program FilesGitHubUnrealEngineEngineBinariesWin64UE4Editor-VSAccessor.dll D:Program FilesGitHubUnrealEngineEngineIntermediateProjectFilesERROR UE4
    Error 3 error MSB3073: The command "….BuildBatchFilesBuild.bat UE4Editor Win64 Development" exited with code -1. C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V120Microsoft.MakeFile.Targets 38 5 UE4

  5. What's nice about this is that, even though they can't use the code directly, other (competing and/or commercial) projects (yes, even Unity if they so wanted) could study and learn from the UE4 code. Not saying the code is easy to learn from or understand (I haven't even seen the code, but odds are it's probably neither of those things), but it is, at least, possible.

  6. If you're a student you can get VS for free from dreams park ^^ you can also get 3ds Max 2014 for free too ^^ forgot the website for 3ds Max just type 3ds Max free for student in Google an you'll find it anyway best of luck an let's create some Epic games ^_^

  7. One question. What's the real advantage of doing it via Code ?

    Seems to me like you could have created the parent "Powerup" class all in Blueprints without any probvlems.

  8. omfg. Compiling is such a pain in the $§$! Gimme an interpreted scripting language like JS in Unity, at least for prototyping reasons.

  9. This is the first video I watched so I would consider buying it or not. But this tutorial is all over the place, lacking good organization. Its left me more confused than anything. Unreal people, please have organized tutorials.

  10. That UPROPERTY didn't work for me (under 4.1) – got errors about multiple visibility defines, this worked (but I don't know what I'm doing at this point….) UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Powerup)

  11. I was hoping for UE4 to be much more user friendly than UE3 but it's still a pain in the ass to understand it …

    It took me 1 weeks to fully understand Unity3D

    Epic please make something more user friendly i don't want to waste 3 years to finaly make something

  12. I have the exact same code as you, but my compiling fails (when you compile at 15:18)
    I get "Found more than one edit/visibility specifier (VisibleDefaultsOnly), only one is allowed"

  13. You lost me at the first line of code because you didn't tell how the UProperty  appeared on the screen!

  14. When I create a new project with code I'm getting the solution only for "Pizza", but I don't have "Engine" into my solution. So I assume that you compiled the engine code. So my question is: it's worth to compile the engine or it's ok with the downloaded binaries?

  15. Is it me or has the syntax for UPROPERTY changed?  Didn't seem to like the 3 parameters I passed in.  But would compile if I provided 2 paremeters: VisibleDefaultsOnly, Category = Powerup

  16. I'd be interested to see a more in depth code tutorial. One that takes you through a complete game from blank to playable / shippable product. That way not only can you see how to reach the point where you had the default side scroller ( so the code in the template) but how to develop from there such as importing models, coding animations and more. Please correct me if you already have video's on such stuff, the titles don't cover everything.

  17. So we're supposed to use Visual Studio, like the worst IDE ever? What about other platforms, why not just give us a customized IntelliJ IDE?

  18. Thanks so much for a great intro tutorial! Are there any plans to have some follow up tutorials on visual studio and unreal? In particular on how to set and work through debugging in a game?

  19. Spend more time on this subject please
    Blueprints itself is very raw and there is no way you can avoid c++
    so you've got the point

  20. the only thing unreal in unrealengine 4 are compilation times, and its all thankfully to the UBT which when usual compilation and linking takes about 2 seconds, with UBT it takes more than 25!  yeah when you start compiling it takes about 10 seconds to fully load UBT which wastes around 400MB of your RAM,why would it load everything when i dont even touch a single header file?
    just look at that:
    i5 3.6ghz:
    Cumulative action seconds (4 processors): 0,63 compiling,  1,03 linking, 
    1>  UBT execution time: 14,90 seconds

  21. So are you pressing F5 to compile and run? Or am I using the wrong button? I don't know VS very well, to be honest so when you're using keyboard shortcuts I'm getting a bit lost.

  22. with UE4 C++ compiling is painful … blueprint is good but i love coding 🙁
    i prefer using UDK With DX11 and keep using UScript better than UE4 with C++ Compiling Pain !

  23. Cool tutorial, but when I first compiled I got 16 errors.  Then I changed the UPROPERTY to contain only two arguments/parameters, and that made it slightly better to where I only got 11 errors.  Something about OVERRIDE being deprecated.  So I lowercased "OVERRIDE" and still have errors.

    One of the errors is "error LNK1104 cannot open file…….somefile.dll".  Any help?

  24. sorry for the noob questions, but whats the difference between using blueprints and c++? can't you do the rotating power up in blueprint as well, without the compile time and shifting back and forth from visual studios to unreal? i was hoping this video would be an introductory video that explained the difference between the 2, the pros and cons of using c++ and BP and when to use it instead of just jumping straight into the code.  

  25. I really appreciate the videos. Thanks guys!

    I have a question though. How would you add the Wedge mesh and the Destroy on Overlap directly with C++ code?

    Thanks again!

  26. The big problem with UE team is they assume newbies that they know many things already. The biggest problem is they never tell in the beginning of their tutorials what a learner should know already. 

  27. Is that autocompletion or what? — lines appear of nowhere;  try to explain the code — what the arguments mean; put some substance in your words — speak a little louder, slower and focus on what is important.
    For example: I have a hunch that once you declared those components "showable" in editor, you can edit/rotate them from there, graphically.
    If you put "intro" in the title then start from the beginning, for beginners.

  28. Is this up to date with 4.6? I've been looking at some 4.6 demos that seem to have a pretty different structure … I'm somewhat confused.

  29. Great video. Thank you for posting.

    NB: All I really needed was to understand how a C++ object became a blueprint object that could be placed in the world. While some of the code used here was depricated, it was easy to find the current syntax in the supplied examples.

    I am still stunned at the power that has been given to the people by Epic Games. I raise my glass in a toast: – May this be the definite end games that look like web-pages! 😉

  30. How is this in anyway an intro to programming tutorial? Great nevertheless but honestly this is advanced game programming.

  31. As a coder, I guess I was hoping for a little more from this video. The predefined game types are great and all, but I was hoping for something a little more technical . What if I want to start with an empty project and add my features from there? As it stands, I can't find any guides on how to make the player use the FPS feature after adding it through the content browser 🙁

  32. I wanna challenge the notion that ue4 doesn't target complete noobs.. have you read some of the shit on the startup templates? "this is popular for action and adventure games"
    .. so like, what? it's aimed at hardcore programmers with shit all gaming experience? why even create things for people like this? they shouldn't be programming games to begin with..

    on the other hand, gamers who are quite aware of what first, third and so on person view side view and so on are, are likely to know less about specific stuff like codethings, and should be the people making cool new games..

    I think I had a point but screw it, leaving this as a rant :b

  33. Hey everyone I just wanted to ask a question. Do you have to be a "master" programmer to use an engine? Cause I am currently studying Java and I consider myself decent. Also seeing that c++ code is being used, should I also learn c++ or stick with java? I never used an engine before.

  34. I think it's impressive that in between all of your knowledge of coding and the layout of the engine you knew how to differentiate between "yaw" and "roll" off the top of your head. Smart man

  35. It's painful having to listen to the speaker say ah or um in just about every sentence. You guy should really have someone redo this tutorial.

  36. UPROPERTY(VisibleDefaultsOnly, Category = Powerup)
    TSubobjectPtr<USphereComponent> TouchSphere;

    This code is deprecated. Use the following code for 4.12

    UPROPERTY(VisibleDefaultsOnly, Category = Powerup)
    USphereComponent* TouchSphere;

  37. And Also, For the cpp code,

    TouchSphere = CreateDefaultSubobject <USphereComponent>( TEXT("TouchSphereComponent"));
    TouchSphere->SetSphereRadius(20.0f, false);
    RootComponent = TouchSphere;
    RotationRate = 180.f;

  38. Well see the problem is I undestand classes, parameters, object etc. I am having a problem with not being familiar to the various types of classes parameters object etc. Any help where did you guys learn this

  39. first, UE4 is complicated engine, which several thing you can't done with code only, but also in blueprints, and definitely i'm not blueprints fan. And thing get even worst when i find no another language except C++, well pick, Hardest language ever i can say, interface when i was in beginner in UE4 like i was in the forest without any guide and don't know how to craft anything and eaten by animals

  40. A lot of built in functions that already do the job,also nice tutorial i find it very helpfull,but would like to see what happens in those built in functions.

Leave a Reply

Your email address will not be published. Required fields are marked *