Book Image

Unreal Engine 4.x Scripting with C++ Cookbook - Second Edition

By : John P. Doran, William Sherif, Stephen Whittle
Book Image

Unreal Engine 4.x Scripting with C++ Cookbook - Second Edition

By: John P. Doran, William Sherif, Stephen Whittle

Overview of this book

Unreal Engine 4 (UE4) is a popular and award-winning game engine that powers some of the most popular games. A truly powerful tool for game development, there has never been a better time to use it for both commercial and independent projects. With more than 100 recipes, this book shows how to unleash the power of C++ while developing games with Unreal Engine. This book takes you on a journey to jumpstart your C++ and UE4 development skills. You will start off by setting up UE4 for C++ development and learn how to work with Visual Studio, a popular code editor. You will learn how to create C++ classes and structs the Unreal way. This will be followed by exploring memory management, smart pointers, and debugging your code. You will then learn how to make your own Actors and Components through code and how to handle input and collision events. You will also get exposure to many elements of game development including creating user interfaces, artificial intelligence, and writing code with networked play in mind. You will also learn how to add on to the Unreal Editor itself. With a range of task-oriented recipes, this book provides actionable information about writing code for games with UE4 using C++. By the end of the book, you will be empowered to become a top-notch developer with UE4 using C++ as your scripting language!
Table of Contents (16 chapters)

Formatting your code (Autocomplete settings) in Visual Studio

Code-writing formatting with Visual Studio is a pleasure. In this recipe, we'll discuss how to control the way Visual Studio lays out the text of your code.

Getting ready

Code has to be formatted correctly. You and your co-programmers will be able to better understand, grok, and keep your code bug-free if it is consistently formatted. This is why Visual Studio includes a number of auto-formatting tools inside the editor.

How to do it...

  1. Go to Tools | Options. Once there, go to the Text Editor | C/C++ section and select it. This dialog displays a window that allows you to toggle Automatic brace completion:

Automatic brace completion is a feature where, when you type {, a corresponding } is automatically typed for you. This feature may irk you if you don't like the text editor inserting characters for you unexpectedly.

You generally want Auto list members on, as that displays a nice dialog with the complete names of data members listed for you as soon as you start typing. This makes it easy to remember variable names, so you don't have to memorize them:

If you press Ctrl + spacebar inside the code editor at any time, the auto list pops up.
  1. Some more autocomplete behavior options are located under Text Editor | C/C++ | Formatting:

I recommend using all of the options at first and then disabling them only if they interrupt your workflow.

You can also autoformat a section of text by highlighting a section of text and selecting Edit | Advanced | Format Selection (Ctrl + K, Ctrl + F).

How it works...

The default autocomplete and autoformat behaviors may irk you. You need to converse with your team on how you want your code to be formatted (spaces or tab indents, size of indent, and so on), and then configure your Visual Studio settings accordingly.