C++, Game Engine, Graphics, Review, Unreal

Review: Learning C++ by Creating Games with UE4 by William Sherif


Right here is a book with a clearly defined goal and an excellent execution. Learning C++ by Creating Games with UE4 by William Sherif takes you on a journey from being a total blank in C++ to coding some basic features of a 3D game. Even though I have been coding in C++ for years, I still enjoy reading novice level texts as sometimes they can teach you a new way of thinking about familiar problems. For me, it’s also important to have good book recommendations (especially for people starting out), and I actually discovered this book from a member of the Unreal Engine community looking for a review. So here it is.

William Sherif starts the book proper, with how to setup a project using either Visual Studio or XCode. This is actually a great design, and it’s thoughtful to include both operating systems (Linux is not officially supported by Epic yet, so I can’t knock the author on that one). When first starting with C++ programming, probably the hardest thing is not the syntax but understanding how to configure the project and settings in the IDE, so I like that this was covered first. Next Sherif moves onto the basics of programming: variables and memory (numbers and pointers), control flow (if, else, equality and comparison), looping (while and for loops), functions and macros, variable scoping, objects and classes, inheritance, and finishing up with dynamic memory allocation and arrays. Really quite a good foundation for learning C++. I found the explanation to be clear and concise, and the author did a good job of easing the reader into the information. C++ is a huge topic to cover, and there are volumes of text many times this size going deeper into the intricacies of the language. I wouldn’t actually fault the book for this, I think it’s a strength. Some novices may be overwhelmed by C++ if they start with something like Stroustrup’s 1,300 page tome. So I would say this is a great introduction to the language, and a great refresher if you’re coming back after a while.

The second half of the book is focused on Unreal development in particular. The author opens by discussing templates and containers in UE4, including some basic ones like TArray, TSet, TMap and then discussing the STL versions of these and how they differ in Unreal. He follows up with the first real example in the engine: an inventory system (with a UI) and the ability to pickup items in the world. I like this approach as it’s a real tangible task that many games would include. The author then shows how to code NPCs that are able to display a text message to the player. Next, Sherif talks about how to create monsters – basically enemy characters that can chase and attack the player. He closes with adding spell casting (including the code and setup of the particle system).

So this is not a book that will show you “How to Make a Complete AAA Game in 24 Hours” but I don’t think that was the intention. What the author does is introduce C++ at the right pace, and also show how to get started with applying that knowledge to developing games in Unreal 4. In some ways, it almost feels like two separate books: one on basic C++ programming, and another on coding in C++ for Unreal Engine 4. This is not necessarily a bad thing, and I think both parts are worthwhile. Really, this book would be most valuable to someone that has little experience with C++ and is also new to using C++ in UE4. If you are already a C++ pro, the first half of the book may seem too basic. However, I think the Unreal coverage can be useful to developers of varying skill levels.

Overall I enjoyed Learning C++ by Creating Games with UE4 and would entirely recommend it to anyone interested in gaining knowledge in C++ for Unreal. To be honest, this is one of the only books out there on the topic right now, so it sort of stands alone. I believe it’s taken me a little over a week to read the 342 page text. Certainly, it doesn’t cover everything you need to know (not even close) but it’s a great place to start. I’d also add that I read the book on the Kindle Fire HDX, and the formatting looked pretty good. The price on the e-book was also much more affordable, so now may be a good chance to upgrade if you’ve still been reading on ink and paper.

3D Engine, Graphics, Tutorial, Unreal

Tutorial: How To Make a Cube Roll On A Grid in Unreal Engine 4

In this tutorial, I will show how to make a cube roll from side-to-side on a grid. This project took me around 3 days to complete, though much of that was wrapping my head around basic things in UE4. Some of the areas explored here include setting up key bindings and action mapping, setting and clearing timers, and rotating around an arbitrary point.

First, you want to start by setting up the action mapping. What this does is basically binds an input button (like a keyboard key) to a particular action (really just a name that you make up). For this test I needed 4 keys for up, down, left and right. Since the arrow keys and WASD were already used by the default Unreal fly camera, I choose to employ the IJKL keys to move the cube around. These options are found in “Settings->Project Settings->Engine->Input->Bindings”.


Next, we will need to connect those actions to a function in order to make something happen on the screen. You can do this by creating an “InputAction” Blueprint and choosing the name you created (like “Action_Up”). I set these actions to call a function I created for this example called “StartMoving”. In some cases, you may want to bind the action to a custom event, which may simplify the code and allow for a cleaner Blueprint (as you can use events to effectively “jump” to other points in the same Blueprint without a line connecting them). In this case, I had to pass in some state (to know which direction the cube is moving) so using a function was better suited for the job.


The “StartMoving” function is not that complex. All it does it check first if the timer is active (to avoid registering input while the cube is already moving), save some state on the cube itself (the direction of movement and it’s last position), and then creates a timer to handle the animation.

The key part is the creation of the timer itself, using “SetTimer”, which is shown below. You can think of a timer as spawning another process or thread that can run concurrently with your main logic. The timer just calls a function of your choice (“MoveTween” in this example), at a specified time interval (use 0.0166 for a 60Hz animation cycle, which looks smooth enough). You can also set whether it loops or not, we use looping in this case.

Finally, we have the “MoveTween” function, which is what is called by the timer and what does all the math calculation to rotate around a particular axis and point in space. It’s also what animates the cube, and clears the timer at the end itself. It’s very useful to be able to spawn a timer, and then have it terminate itself when necessary. The full function is shown below.


Really, the core math of the method is done by two function included in UE4, “RotateVectorAroundAxis” and “RotatorFromAxisAngle”. We first create a axis based on the movement direction. Then we subtract the pivot point (in our case, the bottom edge of the cube), rotate around that axis, and then add the pivot point back to the location. The rotation around axis logic is actually based on an example shown on the Unreal Answer Hub, though it was modified to fit my purpose.


And that is basically it. I’ve even included the full project file below for you to download and experiment. I imagine this type of motion could be used for a type of puzzle game created in Unreal Engine 4. Download Link: UE4.7.4 Cube Motion Project Files

3D Engine, Graphics, Tutorial, Unreal

Tutorial: How To Make a Textured Spinning Cube Using Unreal Engine 4


Today I will show how to create a textured spinning cube using Unreal Engine 4. Making a cube spin is basically what I consider the “litmus test” of 3D engines. How long it takes you to figure this out will show how convenient or capable the engine is. While I might have skipped this test (by jumping straight into creating Pong) I thought it was worthwhile to go back and try it. Hopefully this tutorial will be helpful to some of you just getting started.


First thing you should do is create a new blank project. I chose to make the project with the starter content (and deleting the furniture) however that won’t be important for this guide. Next look on the left-hand panel, make sure you are in place mode (the icon with the cube), and look under basic and find Cube. Now drag the cube into the scene. It will probably start inside the floor, so just press Q to go into move mode and then drag it up a little.


Since looking at a gray model is not that exciting, lets add some texture. In the Content Browser on the bottom, right-click in the empty area and select “Import to /Game…”. Then find your image file and press Open.


You should see the new texture appear in the browser. Now drag this texture onto the cube model. You’ll see this automatically create a default material for you. With the cube still selected, click “Movable” in the Details panel on the right.


The next step is to create the component Blueprint. You can do this by clicking the green “+Add Component” button on the top of the Details panel. Choose “New Blueprint Script Component”. In the pop-up window, pick Scene Component, click Next, type a name in, then click “Create Blueprint Class”.


In the new Blueprint window, you can delete the “Event Initialize Component” (though you can also leave it alone, won’t matter in this case). Pull off the output execution pin on “Event Tick” (it’s the white arrow looking thing on the upper-right). You should see a menu open. Start typing “rotation” and then pick “Add Relative Rotation”. In the Y field for “Delta Rotation” type in “1” and press Enter. Pull off the “Target” pin and type “parent” then click “Get Attach Parent”. Now you can save and compile the script.


Switch back to the main editor window and press “Play”. That’s it! Hopefully this tutorial was useful to some people (please let me know in the comments). I plan to produce more of these in the future, and they should gradually get more complex as I get more familiar with the engine.

It’s really quite amazing how quick and easy it is to work with Unreal. Using straight C++ and DirectX, one would be lucky to make a textured spinning cube in 2 hours, let alone 2 minutes. It really speaks to the robustness of the engine. Of course, I still have a long way to go in terms of learning the engine, so please follow me on this journey (and pray I don’t give up on this one).

3D Engine, Game Engine, Gaming, Graphics, Unreal

Making Pong in Unreal Engine 4 (My Very First UE4 Game!)


Today I’d like to unveil what I’ve been working on for about 2 weeks: Pong in Unreal Engine 4. Most of that time was spent reading documentation and watching tutorial videos just to figure out the basics. There is actually a *lot* of good material out there for Unreal Engine 4, the docs have been helpful and there are plenty of videos. Disappointingly, there are barely any books out there for the engine, but I’m sure that will change quickly.

Pretty much anyone will tell you, when you are learning to develop games (or switching to a new engine/platform), the best thing to do is to start small and try to complete something. It’s really silly to try to make an MMORPG as your first game (I have fallen for this one!) and even relatively simple things can become complex fast when you are not familiar with the platform. So I chose to do Pong as my first excursion into Unreal 4. It was not without some trials, but I made it through alive. Oh, and, no. This will not be considered my “finished project of the new year”. There are some other, cooler, things I have in mind.

Previously I was making multi-part blog posts with basically quick status updates. This was fine, but I think it will be more helpful for the community for me to do focused tutorials on a specific topic and post those more frequently. I learned quite a lot about Unreal with this project, and I think I can share some of that on this site. Some of the things I picked up working on this demo include: importing assets, working with Blueprint, basic flow and logic, movement, collision, HUD, events, keyboard control, functions and variables, and just getting familiar with the Unreal Editor interface. Not sure I will make tutorials on everything, but I plan to break this into a few posts. Below you can see the level Blueprint for the game, just to give you an idea of the complexity.


Overall I have been impressed with Unreal Engine 4, and I can’t imagine purchasing a more capable piece of commercial software for less than the pennies they are giving this away for. People can complain about the 5% royalty but, really, if you get to the point where 5% is a significant dollar amount, you will be rolling in the the dough and shouldn’t care if Epic wants a piece of the pie. Cost aside, I do like the engine a lot. Granted, I ran into some bugs, and more crashes and stability issues than I’d care to admit. At one point, the project saved in a corrupted state and I was blocked from even opening it at all. Luckily, I was able to update the engine and convert the project, but I was sweating pretty hard for a little while. That said, I’m sure this can be improved in time and it didn’t stop me from developing (I’d just recommend using source control and committing often).

The visual programming system, Blueprint, is very powerful and I used that alone for this demo (no C++). I did start checking out the C++ support and it seems to add some extra power and flexibility, but I haven’t got that far yet. However, I can see building some simple games and experiences using the visual coding by itself. This is also great for designers, who may be able to rig up some basic stuff themselves. Keep in mind, it’s still programming (just not with text). You have to understand the basics of logic and control flow and, in some ways, it may even seem alien to veteran programmers. I know there were definitely a few cases where I had a non-trivial amount of nodes and connections and thinking “I could have done this in 1 line of code”. Once I got beyond that, I think I may prefer it to coding manually, as it’s much harder to make mistakes (or to create stuff that doesn’t work).

I hope to continue working with UE4 in the future and I’ll continue updating my blog as I make major developments. Thanks for watching.