-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
CheatSheet.tex
204 lines (182 loc) · 10.6 KB
/
CheatSheet.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\usepackage{microtype}
\usepackage{multicol}
\usepackage{tabularx}
\usepackage{listings}
\usepackage[
type={CC},
modifier={by-nc-sa},
version={4.0},]{doclicense}
\usepackage[left=0.5cm,right=0.5cm,top=1cm,bottom=1.5cm]{geometry}
\begin{document}
\begin{multicols*}{2}
%\maketitle
\begin{center}
\Huge{Unreal Engine 4 C++ Cheat Sheet}
\linebreak
\Large{(C) J. Böhmer, March 2018 \linebreak Licensed under CC BY-NC-SA 4.0}
\linebreak
\Large{Version 1.0}
\end{center}
\section{Reflection System}
\subsection{UPROPERTY()}
\begin{tabularx}{\columnwidth}{|l|X|}
\hline \textbf{BlueprintAssignable}
& Multicast Delegates only. Exposes property for assigning in Blueprints \\
\hline \textbf{BlueprintCallable}
& Multicast Delegates only. Property property for calling in Blueprints \\
\hline \textbf{BlueprintReadOnly}
& This property can be read by blueprints, but not modified \\
\hline \textbf{BlueprintReadWrite}
& This property can be read or written from a blueprint \\
\hline \textbf{Category}
& Specifies the category of the property within the Editor. Supports sub-categories separated by "$\vert$" \\
\hline \textbf{EditAnywhere}
& Indicates that this property can be edited via property windows, archetypes and instances within the Editor \\
\hline \textbf{EditDefaultsOnly}
& Indicates that this property can be edited by property windows, but only on archetypes. This operator is incompatible with the Visible* specifiers \\
\hline \textbf{EditFixedSize}
& Indicates that elements of an array can be modified in Editor, but its size cannot be changed \\
\hline \textbf{EditInstanceOnly}
& Indicates that this property can be edited by property windows, but only on instances, not on archetypes \\
\hline \textbf{Transient}
& Property is transient: shouldn't be saved, zero-filled at load time \\
\hline \textbf{VisibleAnywhere}
& Indicates that this property is visible in property windows, but cannot be edited at all \\
\hline \textbf{VisibleDefaultsOnly}
& Indicates that this property is only visible in property windows for archetypes, and cannot be edited \\
\hline \textbf{VisibleInstanceOnly}
& Indicates that this property is only visible in property windows for instances, not for archetypes, and cannot be edited \\
\hline \textbf{AdvancedDisplay}
& Moves the property into the Advanced dropdown in the Details panel within the Editor \\
\hline \textbf{EditCondition (Meta)}
& The property can only be edited in Editor if the specified bool Property is true. Use ! to invert logic (so you can only edit property if bool is false). \\
\hline
\end{tabularx}
%Usage example:
\begin{verbatim}
UPROPERTY(EditAnywhere, Category="Category|Sub")
bool BoolProperty;
UPROPERTY(BlueprintReadOnly, AdvancedDisplay)
TSubclassOf<UStaticMesh> AdvancedMeshClass;
UPROPERTY(meta=(EditCondition="BoolProperty"))
uint16 ConditionalInt;
\end{verbatim}
\subsection{UCLASS()}
\begin{tabularx}{\columnwidth}{|l|X|}
\hline \textbf{Abstract}
& A class that is marked as abstract can not be placed or instanced during runtime. This is especially useful for classes, that does not provide functionality on their own and must be inherited and modified for meaningful usage.\\
\hline \textbf{Blueprintable}
& Classes marked with this attribute can be used as a base class for creating Blueprints. On Default this is deactivated. The attribute is inherited by child classes, use NotBlueprintable on childs to disable this. \\
\hline \textbf{BlueprintType}
& Classes with this attribute can be used as variable type in Blueprints. \\
\hline \textbf{Placeable}
& Classes marked as Placeable, can be created and placed in a level, UI Scene or Blueprint via the Editor. The flag is inherited by all child classes, use NotPlaceable on child to disable this. \\
\hline
\end{tabularx}
\begin{verbatim}
UCLASS(Blueprintable)
class MyClass : public UObject {
//Class code ...
}
\end{verbatim}
\subsection{UFUNCTION()}
\begin{tabularx}{\columnwidth}{|p{4.1cm}|X|}
\hline \textbf{BlueprintAuthorityOnly}
& This function will not execute from Blueprint code if running on something without network authority \\
\hline \textbf{BlueprintCosmetic}
& This function is cosmetic-only and will not run on dedicated servers \\
\hline \textbf{Blueprint-ImplementableEvent}
& This function is designed to be overriden by a blueprint. Dont provide a body for this function in C++. \\
\hline \textbf{BlueprintNativeEvent}
& This function is designed to be overriden by a blueprint, but also has a native implementation. Provide a body named [FunctionName]\_Implementation \\
\hline \textbf{BlueprintPure}
& This function has no side effects on the object. Useful for "Get" functions. Implies BlueprintCallable \\
\hline \textbf{BlueprintCallable}
& This function can be called from Blueprints and/or C++. \\
\hline \textbf{Category}
& Specifies the category of the function within the Editor. Supports sub-categories separated by "$\vert$" \\
\hline \textbf{Exec}
& This function is callable from the Console CLI. \\
\hline
\end{tabularx}
%\textbf{Usage example:}
\begin{verbatim}
UFUNCTION(Exec)
void ConsoleCommand(float param);
UFUNCTION(BlueprintPure)
static FRotator MakeRotator(flat f);
UFUNCTION(BlueprintImplementableEvent)
void ImportantEvent(int param);
\end{verbatim}
\section{Classes and Functions}
\subsection{Base Gameplay Classes}
\begin{itemize}
\item \textbf{UObject:} The base class, all classes, that should be used within C++ must extend. The name of child classes should start with U (e.g. UMyNewClass).
\item \textbf{AActor:} Actor is the base class for all objects, that can be placed in a level. An Actor can have various Components. Child classes should start with A (e.g AMyNewActor).
\item \textbf{APawn:} The base class, for all actors, that should be controled by players or AI.
\item \textbf{ACharacter:} Characters are Pawn, which has a mesh collision and movement logic. They represent physical characters in the game world and can use CharacterMovementComponent for walking, flying, jumping and swiming logic.
\item \textbf{UActorComponent:} The base class for all actor components. Components defines some reusable behavior, that can be added to different actors.
\item \textbf{USceneComponent:} An Actor Component, which has a transform (position and rotation) and support for attachements.
\item \textbf{UPrimitiveComponent:} A SceneComponent which can show some kind of geometry, usable for rendering and/or collision. Examples for this type are \emph{StaticMeshComponent}, \emph{SkeletalMeshComponent}, or the \emph{ShapeComponent}s.
\end{itemize}
\subsection{Datastructures and Helpers}
\begin{itemize}
\item \textbf{TArray:} The mostly used container in UE4. The objects in it have a well-defined order, and functions are provided to create, get, modify or sort the elements. Similar to C++'s std::vector. You can iterate over the element like this:
\begin{verbatim}
for (AActor* Actor : ActorArray) {
Actor->SomeFunc(); }
\end{verbatim}
\item \textbf{TMap:} A container, where every element has a key (of any type), via which you identify every element. Similar to std::map
\item \textbf{TSet:} A (fast) container to store unique elements without order. Similar to C++'s std::Set
\item \textbf{TSubclassOf:} When you define a UProperty with the type TSubclassOf{\textless}UMyObject{\textgreater}, the editor allows you only to select classes, which are derived from UMyObject.
\item \textbf{FName:} FNames provide a fast possibility to reference to things via a name. FNames are case-insensitive and can not be manipulated (they are immutable).
\item \textbf{FText:} FText represents a string that can be displayed to user. It has a built in system for localization (so FTexts can be translated) and are immutable.
\item \textbf{FString:} FString is the only class that allows manipulation. FStrings can be searched modified and compared, but this makes FStrings less performant than FText or FName.
\end{itemize}
\subsection{Useful Functions}
\begin{itemize}
\item \textbf{UE\_LOG():} This functions allows to print message to the UE Log or the Output Log in the Editor. You can set a category (you can use LogTemp for temporal usage) and verbosity (like Error, Warning or Display). If you want to output a variable, you can use printf syntax. Usage Example:
\begin{verbatim}
//Print Test to console
UE_LOG(LogTemp, Warning, TEXT("Test"));
//Print the value of int n and a string
UE_LOG(LogTemp, Display, TEXT("n=%d"), n);
UE_LOG(LogTemp, Error, TEXT("%s"), MyString);
\end{verbatim}
\item \textbf{AddOnScreenDebugMessage():} If you want to print a debug message directly to the screen you can use AddOnScreenDebugMessage() from GEngine. You can specify a key, displaying time and display color. A message overrides an older message with the same key. Usage example:
\begin{verbatim}
GEngine->AddOnScreenDebugMessage(-1, 5.f,
FColor::Red, TEXT("5 second Message"));
//Use FString, if you want to print vars
GEngine->AddOnScreenDebugMessage(-1, 5.f,
FColor::Red,
FString::Printf(TEXT("x: %f, y: %f"), x, y));
\end{verbatim}
\item \textbf{NewObject():} NewObject() creates a new UObject with the specific type. Objects created using NewObject() are not visible to the Editor, if you need that, use CreateDefaultSubObject() instead. Usage example:
\begin{verbatim}
auto RT = NewObject<UTextureRenderTarget2D>();
\end{verbatim}
\item \textbf{CreateDefaultSubobject():} This function creates a new named UObject with the specific type in the context of the current actor. Created objects are visible to the Editor, but this function can only be used in constructor. Usage example:
\begin{verbatim}
auto Mesh = CreateDefaultSubobject
<UStaticMeshComponent>(FName("Mesh"));
\end{verbatim}
\item \textbf{LoadObject():} This function loads an object from a specific asset. Usage example:
\begin{verbatim}
auto Mesh = LoadObject<UStaticMesh>(nullptr,
TEXT("StaticMesh'/Asset/Path/Mesh.Mesh'");
\end{verbatim}
\item \textbf{Cast():} Casts an object to the given type. Returns nullptr if the object is not castable to this type. The object that should be casted, must be based on UObject, to work properly.
Usage example:
\begin{verbatim}
AActor* Actor = Cast<AActor>(Other);
if(Actor != nullptr) {
/* do something */ }
\end{verbatim}
\end{itemize}
\doclicenseImage
\end{multicols*}
\end{document}