Unreal Engine and C++ We’re finally at a point where we can start working in C++ with Unreal Engine To get everything set up for this properly, we’re going.

Slides:



Advertisements
Similar presentations
Getting started with MPLAB Launch MPLAB Set Toolbar as in the next slide by clicking the leftmost icon Open a new Source file by choosing [FILE][NEW] Type.
Advertisements

Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
Using XCode © 2013 Surajit A Bose De Anza College.
Note if in doubt click the “Help” button
HELLO WORLD: YOUR FIRST PROGRAM CHAPTER Topics  Hello World?  Creating a Unity Project –The Unity Project Folder  MonoDevelop: Unity's Code Editor.
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
Adding Controls to User Forms. Adding Controls A user form isn’t much use without some controls We’re going to add controls and write code for them Note.
The basics of the Online Portal
A First Program Using C#
05/09/ Introducing Visual Basic Sequence Programming.
Introduction to the WebBoard Terry Dennis. The WebBoard - Our Connection The WebBoard URL is
Playing Music in Alice By David Yan Under the direction of Professor Susan Rodger July 2015.
Alice 2.0 Introductory Concepts and Techniques Project 1 Exploring Alice and Object-Oriented Programming.
Diagnostic Pathfinder for Instructors. Diagnostic Pathfinder Local File vs. Database Normal operations Expert operations Admin operations.
Unit 1: Java and Eclipse The Eclipse Development Environment.
Playing Music in Alice By David Yan Under the direction of Professor Susan Rodger July 2015.
Using Microsoft Visual Studio 2005 Original by Suma Rao Revised by John G. McMahon ( 9/6/2008 )
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Game Maker – Getting Started What is Game Maker?.
How to Setup and Score a Tournament May Let’s Get Organized The setup and organization outlined in this clinic are suggested steps however can be.
How to use By Lauren Fowler. Adding Attachments Attachments are pictures, videos and files that you have on your computer. You can add these to.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Lecture Set 2 Part A: Creating an Application with Visual Studio – Solutions, Projects, Files 8/10/ :35 PM.
1 Getting Started with C++ Part 1 Windows. 2 Objective You will be able to create, compile, and run a very simple C++ program on Windows, using Microsoft.
Using Microsoft Office Word Assignment Layout. Target Create a Cover Page (Front Page) Create a Table of Contents Page Create a Table of Figures Page.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
Digital Game Design ACST 3710 Your First Unity Program 1.
Dive Into® Visual Basic 2010 Express
The eclipse IDE IDE = “Integrated Development Environment”
Development Environment
Chapter 2: The Visual Studio .NET Development Environment
Using Mail Merge for Lotus Notes
Eclipse Navigation & Usage.
– Officiating Management Software
Using Visual Studio with C#
KELLER WILLIAMS REALTY
Introduction to Object-Oriented Programming
Unit 7 – Excel Graphs.
File Handling Programming Guides.
Conditions and Ifs BIS1523 – Lecture 8.
OOP Paradigms There are four main aspects of Object-Orientated Programming Inheritance Polymorphism Abstraction Encapsulation We’ve seen Encapsulation.
Editable Attributes (1)
UNITY TEAM PROJECT TOPICS: [1]. Unity Collaborate
CIS16 Application Development Programming with Visual Basic
How to Run a Java Program
1. Open Visual Studio 2008.
Items, Group Boxes, Check Boxes & Radio Buttons
Fundamentals of Data Structures
We’re moving on to more recap from other programming languages
Introduction to TouchDevelop
How to Run a Java Program
Game Loop Update & Draw.
Tonga Institute of Higher Education
Introduction to Object-Oriented Programming in Alice
Using Templates and Library Items
[Update Medical Records] Worker Register
Creating the First Program
Visual Basic Menu Editor
Using screens and adding two numbers - addda.cbl
An Introduction to Debugging
Scripts In Matlab.
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Review of Previous Lesson
Drupal user guide Evashni Jansen Web Office.
Web Programming and Design
四時讀書樂 (春) ~ 翁森 山光照檻水繞廊,舞雩歸詠春風香。 好鳥枝頭亦朋友,落花水面皆文章。 蹉跎莫遣韶光老,人生唯有讀書好。
Chapter 2 part #1 C++ Program Structure
Selenium IDE Installation and Use.
Presentation transcript:

Unreal Engine and C++ We’re finally at a point where we can start working in C++ with Unreal Engine To get everything set up for this properly, we’re going to need an IDE to create C++ files in Which Unreal Engine can link to

Unreal Engine and C++ As of Unreal Engine 4.18, we can use Visual Studio Code as a C++ IDE And Unreal Engine will act as the compiler This is a lightweight application that acts as a text editor Though has many extensions for supporting syntax highlighting, code completion, and debugging For lots of different languages Make sure these are definitely installed before moving on Windows: Latest Visual Studio Community Edition 2015/2017 Mac: Latest XCode

When making a new project, we see two tabs at the top Making a C++ Project To use C++ in an Unreal Engine project, we actually need to use a different project type When making a new project, we see two tabs at the top Blueprints C++

Feel free to keep the starter content Making a C++ Project Make sure that C++ is selected Then select Basic Code Give it a location/name Then click on Create Project Feel free to keep the starter content

Making a C++ Project Two things will happen here Unreal Engine will open as normal (like it does whenever we make a project) The default C++ IDE will open as well Windows: Visual Studio 2015/2017 Mac: Xcode If the program crashes, it’s most likely due to 4.18 requiring the latest updates for Visual Studio/Xcode If an earlier Unreal Engine is installed (like 4.16), feel free to use that for now And repeat the earlier steps to make the C++ project

The IDE will take quite a while to get set up Making a C++ Project The IDE will take quite a while to get set up This is because it has to look through all the C++ files in the project Including all the C++ files in Unreal Engine as a whole

Making a C++ Project Ex First, make sure the latest version of Visual Studio 2015/2017 or XCode is installed Then run Unreal Engine Create a new C++ project Choose the Basic Code template Choose its name and location Click on Create Project

Opening a C++ File In Unreal Engine, most C++ files act as templates to be used Like parent classes Once a C++ file has been made, we decide how it works Afterwards we make an item in Unreal Engine and make it extend the C++ functionality

Opening a C++ File We can see all the C++ files the project uses from the Content Browser Click on the Folder icon near the top Choose C++ Classes Here we’ll see everything it contains so far

Opening a C++ File All C++ Basic Code projects start with a single C++ file The Game Mode of the current level Let’s look at this file in our C++ IDE

Opening a C++ File The IDE project actually contains two key areas The source code of the engine itself The source code of the project This is separated into two folders: Engine and Games Expand the Games folder Expand the Project folder Expand the Source folder Expand the Project folder inside This is where all the C++ files will go

Opening a C++ File The C++ source (.cpp) and header (.h) files for the project itself are here Leave them alone, as they attach any C++ code to the project There’s also the GameModeBase files Let’s open both the header and source files

Opening a C++ File The source file is empty (we’ll ignore it for now) The header file has some interesting code here

Opening a C++ File Every header file has The namespace (the project’s name) The class name (prefixed with a letter) A class to extend

Opening a C++ File The GENERATED_BODY() function is required It lets Unreal Engine make all the necessary files for this class It has to be the first line inside the class So don’t move it

Opening a C++ File Let’s tweak this file slightly We’ll add a constructor to the header file Note that we need to use the same name as the class And we need to put it in the public section

Opening a C++ File We’ll then implement this constructor in the source file We’re going to make it output “Hello World” to the console But how can we do that?

Opening a C++ File Unreal Engine has a UE_LOG function Lets us output text to a log Need to specify Which log to use The type of log it is The text to output

Opening a C++ File There are a few types of log Fatal: prints to log and file, and crashes the game Error: prints to log and file (appears red) Warning: prints to log and file (appears yellow) Display: prints to log and file (appears default colour) Verbose: prints to file only

Opening a C++ File Any time we make a change to a C++ file, we need to tell Unreal Engine to compile those files We do not compile from the IDE We can do that by clicking on the Compile button near the top of the editor

Opening a C++ File After some compilation, it’ll say Compile Complete near the bottom of the screen Now lets change the GameMode of this level to this class Done in the Blueprints menu In GameMode Here we select the C++ file

Opening a C++ File With that selected, we’re nearly ready to test this First we need to show the log in the editor So we can see our output This is done from the Window menu Developer Tools  Output Log

Opening a C++ File Let’s run the game and see if we can spot the output It can be hard to spot, but it’s there!

Opening a C++ File Ex In your IDE, go to the [ProjectName]GameModeBase files Games  [ProjectName]  Source  [ProjectName] Open both the header and source files Make a public constructor in the header file, and implement it in the source file Make it output some text to the log Using UE_LOG Save the file, and compile it from the Unreal Engine editor While it’s compiling, open the Output Log window Once compiled, run your game and look for your output in the log

Creating an Actor (1) Just editing this GameMode would by pretty dry Let’s try creating our own Actor class At any point in the Content Browser, we can right-click to add a file At the very top, we’ll see New C++ Class

Creating an Actor (1) Clicking on this option opens a familiar window Looks like the New Blueprint window That’s because we can make a lot of the same files here We’ll click on Actor, and then Next

Creating an Actor (1) We then need to decide on It’s name: this is what we’d refer to it as in Unreal Engine It’s location: which we always leave alone If it’s public or private Public classes can be used in other projects Private classes cannot We’ll choose public for this one, and we’ll call it RotatingCube Can finish by clicking on Create Class

This adds two files in a Public and Private folder Creating an Actor (1) This adds two files in a Public and Private folder The header and source files

Creating an Actor (1) We have the class name Also has GENERATED_BODY() Prefixed with A like before Also has GENERATED_BODY() But it has some more functions this time A constructor The BeginPlay function The Tick function

Creating an Actor (1) The BeginPlay and Tick functions work like the events do in a Blueprint Whenever these events are triggered, these functions are called first Then the Blueprint logic

Creating an Actor (1) Let’s go to the source file and see these functions They are all here, and ready to go

Creating an Actor (1) The constructor sets a Boolean flag to true This lets the actor tick Meaning we can run some logic every update The BeginPlay and Tick functions simply run their parent’s version We need to keep these here As they help Unreal Engine position and render the actor

Creating an Actor (1) Let’s output something to the log when this actor appears in the level Via BeginPlay We’ll then compile our code

Creating an Actor (1) Ex Right-click anywhere in your Content Browser And select New C++ Class Select Actor as the parent class Call it RotatingCube Make the class Public In your IDE, open the source file of this class Add a log message to the BeginPlay function Compile your C++ code in the Unreal Engine editor

Creating an Actor (2) Whenever we make a C++ class like this, we need to make a Blueprint for it Otherwise we can’t use it in the game As such, C++ class act as abstract parents We can’t use them directly But we can make children that use them We’re going to make a folder in the Content Browser for any actors we make

Creating an Actor (2) Inside here, we’ll make the Blueprint By right-clicking And choose New Blueprint Class Here, we usually select one of the main options This time we’re going to go into More Classes at the bottom

Creating an Actor (2) Here we can search for the class we made RotatingCube It appears as an option We’ll select that one and click on Select

Creating an Actor (2) We’ll call this Blueprint RotatingCube_B There’s nothing wrong with using the same name But if we’re making a C++ class that acts as an object, it’s best to give the Blueprint class a different name To show that it is the Blueprint version

Creating an Actor (2) With it made we can open it in the Blueprint editor Let’s give it a StaticMesh So it’s visible in the scene

Creating an Actor (2) With the Blueprint set up, let’s add one of these to the scene Once done, we can play the game

Creating an Actor (2) When we play, we can see the output in the log! We’re now ready to add some more complex logic to this Actor!

Creating an Actor (2) Ex Make a folder in the Content Browser for your “Actors” Create a Blueprint in this folder Using the C++ class you made as its parent Call it RotatingCube_B Open it in the Blueprint Editor, and give it a StaticMesh To make it visible in the scene Add one of these to the scene, and play the game Make sure you see the output for the Actor in the output log

Transforming Actors in C++ If we want to make this cube rotate, we would have added a AddRotation node to the Tick event in the Blueprint However, this C++ class is made for this rotating-ness So we can ‘hard-code’ it into the Tick event in C++

Transforming Actors in C++ To do this, we’re going to add three instance variables to the header file The rotation speeds in the X, Y, and Z axes These are going to be floats As Unreal Engine uses floats to store accurate decimal values We’ll make them in a private section Remember that classes are private by default!

Transforming Actors in C++ We’ll then give these values in the constructor We’ll set the X to 180 And Y and Z to 0 These are going to be degrees per second

Transforming Actors in C++ If we want to rotate the Actor, we can use the AddActorWorldRotation function The same as the Blueprint node! For this though, we need a Rotator object

Transforming Actors in C++ We create a Rotate using the FRotator data-type It is a struct that contains variables for The pitch (Y rotation) The yaw (Z rotation) The roll (X rotation)

Transforming Actors in C++ As this is a value (not a reference), this Rotator will not exist outside this function So no memory management to worry about

Transforming Actors in C++ However, just this isn’t good enough As we’re going to add 180 degrees every tick We want it to be every second So we have to multiply each value by DeltaTime DeltaTime is the amount of time elapsed since the previous tick It keeps games running frame independently

Transforming Actors in C++ We can then pass this Rotator into the AddActorWorldRotation function!

Transforming Actors in C++ If we compile our C++ code and run the game, we’ll see the cube now rotates!

Transforming Actors in C++ Ex Make three private instance variables in the Actor’s C++ class For the rotation speed in each axis Give them any values you want in the constructor In the Tick function, make a FRotator object By passing in these three variables Multiplied by the DeltaTime Run the AddActorWorldRotation function, passing in the FRotator Compile your C++ code, and run your game Make sure the cube rotates!

Random Rotation Ex Use FMath::RandRange(min, max) to get a random number 𝑀𝐼𝑁≤𝑥≤𝑀𝐴𝑋 Use this to assign random rotation speeds in the BeginPlay function Compile your code, and run your game a few times Make sure the rotation is randomised each time!

END OF UNIT!