SylarAtomic's Unreal Engine Notes

C++

Unreal Engine programming is done with C++, therefore it is important to have some C++ notes. I found the C++ Cheat Sheet from Hackr.io is a great start.

Ari's Unreal Engine Notes

If you haven't heard about Ari, Ari is an Evangelist at Epic Games. He is EPIC ;-) (See what I did there?) Ari has a set of notes for Unreal Engine and is where I got the idea to start making my own set.

Make sure to also check out Ari's website https://ari.games. He has a wealth of industry knowledge and his vidoes are always full of passion and enthusiasm!

Sylar's Unreal Engine Notes

Below you will find all my notes that I have made along my way. Just as Ari did for me, I would like to encourage you to make your own notes!

Root Component

Every class that inherits from Actor has a Root component already set up called RootComponent Items can be attached to this by calling

BaseMesh->SetupAttachment(RootComponent);

Forward Declaring

In the .h file, you forward declare by using the class specifier.

class USpringArmComponent* SpringArm;

Forward declaring is a way of telling the compiler about a class or function without declaring it in the header file. You want to do this for two reason, to prevent circular dependencies and reduce compile times. Circular dependecies is when you have Class A that depends on Class B, Class B that depends on Class A and the compiler may not be able to compile the code as it can get stuck trying to always include the other file. Forward declaring is to reduce compile times and the overall header file size. For more information, have a look at the excellent video by Mike Stevanovic Unreal Engine C++ Guide - Forward Declarations

Casting

Casting is when you need to convert a data type from one type to another. Essentially, you have an object, but you want to call a function on its base object (The object it was derived from).

ATank* Tank;
Tank = Cast<ATank>(UGameplayStatics::GetPlayerPawn(this, 0);)

UPROPERTY Macro

When working with variables inside C++ header files: If you want a variable to be declared during the Constructor and keep its variable for use later on, make sure to give it the UPROPERTY Macro.

UPROPERTY()

Spawning and attaching an Actor to another Actor

    UPROPERTY(EditDefaultsOnly, Category = "Window Scenes")
    TSubclassOf<class AWindowActor> WindowActors_ThreeBots;
   
    UPROPERTY()
    AWindowActor* CurrentWindowActor;
// Spawn the actor
CurrentWindowActor = (AWindowActor*) GetWorld()->SpawnActor(WindowActors_ThreeBots);

// Attach to Actor Root
CurrentWindowActor->AttachToComponent(Root, FAttachmentTransformRules::KeepWorldTransform);

The AWindowActor is the C++ class, and WindowActors_ThreeBots is the BP class derived from the C++ class. Make sure in the BP Class that DefaultSceneRoot is set to Movable!

AttachToComponent returns a bool value. This is useful for checking that the attach was sucessful.

Alternatively, make sure to set DefaultSceneRoot to moveable in the constructor:

    // Get the DefaultSceneRoot component of the child actor
    USceneComponent* DefaultSceneRoot = ChildActor->GetRootComponent();


    // Set the mobility of the DefaultSceneRoot to movable
    DefaultSceneRoot->SetMobility(EComponentMobility::Movable);

Short Cuts

Open CPU profiling Ctrl + Alt + Space Ctrl + Shift + ,

Show FPS Ctrl + Shift + H

Search for files (BP_Building) or types ('Static Mesh) Ctrl + P

Opens Content Drawer Ctrl + SpaceBar

Miscellaneous

Coding Principles by SylarAtomic