TIL: Learn to Code in C++ by Developing Your First Game (Section 3, Lectures 59-65)

Interesting, the layout has been changed on the Udemy course, and while I was previously prepared to start Lecture 59 today, it looks as though I’m now at Lecture 65. I’m not sure how exactly the course structure has changed, but it doesn’t look as though I’ve missed anything. Meanwhile, this series of lessons sees us learn how to access transform information, manipulate transform information, do some basic layout of geometry, use the UPROPERTY macro, and use a trigger in combination with the player to open the door.

Section: 3 – Building Escape – Your First Unreal / C++ Game

Lecture 59: Getting Transforms in C++

– Introduces FVector
– Mixes . and -> to access methods
– multiple format operators
– finish PositionReport

IntelliSence seems to be what allows us to do auto-completion. When we type something like GetOwner, there will be no more members available to us if we type . however if we use -> we will get many more options. Just the same, once we type GetActorLocation(), we will have options if we type . and the one we need is ToString().

FString ObjectPos = GetOwner()->GetActorLocation().ToString();

Ben does it a little differently. He uses GetOwener()->GetTransform().GetLocation().ToString()

GetActorLocation returns an FVector, while GetTransform returns an FTransform. The GetTransform is a struct which contains multiple sets of information, which is why we need to additionally use GetLocation().

He suggests that he chose GetTransform because: “I want to reinforce the idea of “drilling-down” to the right type, and to be sure getting the transform of the thing the component is attached to.”

Lecture 60: Moving Objects With C++

pitch_roll_yaw-FRotator
-SetActorRotation()

We place a door into the scene so that we can control its rotation, and then we will add a New Actor Component onto it called OpenDoor…

For some reason… last time I created a component, it didn’t add it into UE4 for me to work with. This time, it’s added in UE4, but OpenDoor.cpp wasn’t loaded automatically into my solution in VisualStudio. :-/

What’s wacky about rotations, is that FRotator() expects our values in Pitch, Yaw, and Roll not X,Y,Z. So in essence rotations are treated with Y up. While everything else is treated as Z up. [insert blank stare emoticon here]

Keep in mind that floats need a decimal.

Lecture 61: Laying out Geometry

-BSP vs Static Meshes
-General viewport workflow

BSP stands for Binary Space Partitioning. “Conceptually, it is best to think of a Geometry Brush as filling in and carving out volumes of space in your level. Long ago, Geometry Brushes were used as the primary building block in level design. Now, however, that role has been passed on to Static Meshes, which are far more efficient. However, Geometry Brushes can still be useful in the early stages of a product for rapid prototyping of levels and objects, as well as for level construction by those who do not have access to 3D modeling tools.” –UE Documentation.

We’ll use the StarterContent architecture static meshes instead. Static Meshes are more efficient, and more customizable — but you need 3D software to make it.

Since this lesson is pretty much just learning to move geometry around, no need for further notes here.

Lecture 62: Applying Materials

These notes are for me, not you. I’ve been using UE4 for a year now… so nothing in this lesson is news to me.

Ben was having difficulty getting the colour he wanted, and so it’s worth mentioning, that you generally will want sRGB preview on when choosing a colour.

Lecture 63: Macros Starting with UPROPERTY

A macro is a programmed cut-and-past operation that happens before code is compiled. Powerful, but can create weird build errors.

We’ll use a trigger volume to trigger the OpenDoor component.

We want a private property that will give us a hard coded angle for the open door.

We also want to make this a UPROPERTY() set to VisibleAnywhere, which will make it visible in the property windows (but not editable). Unfortunately, the specifiers are not included in IntelliSence, and thus you need to go to the documentation in order to figure out what’s what.

We are using
VisibleAnywhere
EditAnywhere

Lecture 64: Using TriggerVolumes

3D Volumes that can detect things entering / leaving. We’ll use IsOverlappingActor() on ATriggerVolume. We’ll use Polling for now, but it’s not optimal. We’ll use Events later.

Be sure to set the door as a moveable object if you want it to be able to move. I used APawn, but Ben uses AActor to track the player as APawn* ActorThatOpens;

We don’t do any sort of action here to close the door. We could in theory do it by setting an additional if statement looking for ReceiveActorEndOverlap, or even just an else statement.

Lecture 65: Unreal’s PlayerController

– GetOwner() goes bottom-up, from child to parent. GetWorld() goes top-down.
– Game Mode specifies the Default Pawn Class
– The Default Pawn is your “body”, and is transient.
– The Player Controller is your “mind” and persists.
– PlayerController class has GetPawn().

It doesn’t make sense to have the player character represented by a UPROPERTY since we can’t select the player in Unreal. We ditch that and go about using a top-down method so that the code can find the player when it executes.

In DoorOpen.cpp we can set ActorThatOpens = GetWorld()->GetFirstPlayerController()->GetPawn(); This will let ActorThatOpens become our player character.