-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
CheatSheet_XL.tex
447 lines (401 loc) · 20.1 KB
/
CheatSheet_XL.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
\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 XL}
\linebreak
\Large{(C) J. Böhmer, March 2018 \linebreak Licensed under CC BY-NC-SA 4.0}
\linebreak
\Large{Version 1.1}
\end{center}
\section{Reflection System}
\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 \textbf{AdvancedDisplay (Meta)}
& List parameter names seperated by commas. Every parameter in this list will appear as advanced pins in Blueprint Editor. \\
\hline \textbf{DevelopmentOnly (Meta)}
& Functions marked like this, will only run in Development builds and not in shipping builds. This is useful for things like Debug Output\\
\hline \textbf{BlueprintProtected (Meta)}
& This function can only be called on the owning object in a Blueprint not on any other instances. \\
\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);
UFUNCTION(meta=(DevelopmentOnly))
float NotSoImportantDebugFunc();
\end{verbatim}
\subsection{UENUM()}
\begin{tabularx}{\columnwidth}{|l|X|}
\hline \textbf{BlueprintType}
& Enums marked with this attribute, can be used from within Blueprints. \\
\hline \textbf{Bitflags (Meta)}
& Enums marked with this attribute, can be used as BitMask in UPROPERTYs. \\
\hline \textbf{DisplayName (UMETA)}
& Use this inside of an Enum, to override the name displayed inside the Editor. See usage below: \\
\hline
\end{tabularx}
\begin{minipage}{\columnwidth}
\begin{verbatim}
//Note that enums must be declared before any class
UENUM(BlueprintType)
enum class ETestEnum {
FirstEntry UMETA(DisplayName="OtherName"),
//...
}
UENUM(meta=(Bitflags))
enum class EMyEnum {
FirstBit,
SecondBit
}
\end{verbatim}
\end{minipage}
\subsection{UPARAM()}
\begin{tabularx}{\columnwidth}{|l|X|}
\hline \textbf{ref}
& By default, when you pass a reference to a Blueprint callable function, it will appear as an output node in the Editor. Use this attribute, to mark it as an input.\\
\hline \textbf{DisplayName}
& Use this name to override the name under which the parameter appears in the Blueprint Editor \\
\hline
\end{tabularx}
\begin{minipage}{\columnwidth}
\begin{verbatim}
UFUNCTION(BlueprintCallable)
void MyFunc(UPARAM(ref) TArray<int>* IntArray);
UFUNCTION(BlueprintCallable)
void OtherFunc(UPARAM(DisplayName="Name" float f);
\end{verbatim}
\end{minipage}
\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{UPROPERTY()}
\begin{tabularx}{\columnwidth}{|p{3.5cm}|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{NoClear}
& Hides the clear and browse button in the editor for this property. \\
\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 \textbf{BitMask (mMeta)}
& Change the value of this property in the Editor using a BitMask, which means you can select the value of each single bits. Use BitMask to specify a Enum, which entries will be used to name each bit. \\
\hline \textbf{ClampMax / ClampMin (Meta)}
& Use this on float or int property, to specify a maximum/minimum, that can be entered for this property in the Editor \\
\hline \textbf {MakeEditWidget (Meta)}
& Use this on a Transform or Rotator property, and the property value can be changed using a widget inside the editor viewport. \\
\hline
\end{tabularx}
%Usage example:
\begin{minipage}{\columnwidth}
\begin{verbatim}
UPROPERTY(EditAnywhere, Category="Category|Sub")
bool BoolProperty;
UPROPERTY(BlueprintReadOnly, AdvancedDisplay)
TSubclassOf<UStaticMesh> AdvancedMeshClass;
UPROPERTY(meta=(EditCondition="BoolProperty"))
uint16 ConditionalInt;
UPROPERTY(meta=(BitMask, BitMaskEnum="EMyEnum"))
int32 BitFlags;
UPROPERTY(meta=(ClampMin="3", ClampMax="4"))
float myFloat;
\end{verbatim}
\end{minipage}
\subsection{USTRUCT()}
\begin{tabularx}{\columnwidth}{|p{3.5cm}|X|}
\hline \textbf{BlueprintType}
& Structs with this attribute can be used as type inside Blueprints. Make and Break nodes get automatically generated.\\
\hline
\end{tabularx}
\begin{minipage}{\columnwidth}
\begin{verbatim}
USTRUCT(BlueprintType)
struct MyStruct {
// ...
}
\end{verbatim}
\end{minipage}
\subsection{Delegates}
Delegates allow to call variable functions via a type-safe way.
There are 3 big types of delegates:
\begin{itemize}
\item Single-cast Delegates, which can have a single function target, declared with \verb|DECLARE_DELEGATE_|
\item Multi-cast Delegates, which can have multiple function targets, declared with \verb|DECLARE_MULTICAST_DELEGATE_|
\item Dynamic Multicasts, which can be serialized, and functions can be found by name, declared with \verb|DECLARE_DYNAMIC_DELEGATE_| or \verb|DECLARE_DYNAMIC_MULTICAST_DELEGATE_|
\end{itemize}
All Delegate macros have the syntax: \linebreak \verb|_DELEGATE_<Num>Params(Name,Param1Type,Param2Type,...)|
or for functions with return value: \linebreak
\verb|DECLARE_DELEGATE_RetVal(RetValType, Name)|
Code example:
\begin{verbatim}
DECLARE_MULTICAST_DELEGATE(VoidDelegate)
DECLARE_DELEGATE_OneParam(IntParamDelegate, int32)
DECLARE_DELEGATE_TwoParams(MyDelegate, int32, AActor*)
DECLARE_DELEGATE_RetVal_OneParam(int, Delegate2, uint8)
void MyFunc;
void MyFunc2(int32);
VoidDelegate Del1;
//Somewhere in func body
Del1.Add(this, FName("MyFunc")); //Add MyFunc
Del1.Broadcast(); //Call all bound functions
IntParamDelegate Del2;
Del2.Add(this, FName("MyFunc2)); //Bind MyFunc2
Del2.ExecuteIfBound(10); //Call MyFunc2
\end{verbatim}
\section{Useful Console commands}
\begin{itemize}
\item \textbf{Show Collision:} Show collision components in game.
\item \textbf{ToggleDebugCamera:} Switch to a separate camera, which you can move in world freely and shows some additional debug infos.
\item \textbf{HighResShot [number]:} Makes a screen shot with [number] times your normal screen resolution. Instead of [number] you can provide a resolution the screenshot should have.
\item \textbf{[CVar] ?:} Add a ? after a CVar name and a description about the CVar will be shown.
\item \textbf{DumpConsoleCommands:} Prints a list of all available console commands and CVars.
\item \textbf{slomo [float]:} Slow down or speed up the game. slomo 1.0 is default. slomo 1.5 is faster than normal, slomo 0.5 is slower.
\item \textbf {open [mapname]:} Load and opens the map with the given name.
\item \textbf{help:} Opens a page in browser which, lists all console commands and variables with a description. Searching and filter for specific commands is possible.
\end{itemize}
%\end{multicols*}
%\pagebreak
%\begin{multicols*}{2}
\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}
TArray<AActor> ActorArray;
//Add MyActor 3 times
ActorArray.Init(MyActor, 3);
ActorArray.Add(AnotherActor);
//Retrieve the first Actor from array
auto FirstActor = ActorArray[0]
//Iterate over all Actor in Array
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
\begin{verbatim}
TMap<int32, FString> StringMap;
StringMap.Add(4, TEXT("Foo"));
StringMap.Add(-1, TEXT("Bar"));
//Iterate over all Pairs
for (auto& pair : StringMap)
{
pair.Key; //Gets the key of the pair
*pair.Value; //Gets the value of pair
}
\end{verbatim}
\item \textbf{TSet:} A (fast) container to store unique elements without order. Similar to C++'s std::Set
\begin{verbatim}
TSet<int32> mySet;
mySet.Add(3); //mySet = [3]
mySet.Add(5); //mySet = [3,5]
mySet.Add(3); //mySet = [3,5]
//Only one 3 can be added to mySet
\end{verbatim}
\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.
\begin{verbatim}
UPROPERTY(EditAnywhere)
TSubclassOf<AActor> ActorType;
\end{verbatim}
\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 and snippets}
\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}
\item \textbf{Console Variables:} To define a variable that can be changed via editor (CVar), you can use TAutoConsoleVariable in any C++ file:
\begin{verbatim}
static TAutoConsoleVariable<int32> CVarMyVar(
TEXT("r.MyVar"),
2, //Default value
TEXT("CVar Description\n")
TEXT(" 1: Infos about possible values \n"),
ECVF_Scalability | ECVF_RenderThreadSafe);
\end{verbatim}
The last parameter are some flags, that defines the behavior of the CVar. When you add ECVF\_Cheat flag, the CVar can be only changed in cheat mode. If you want to access the CVar's value in C++, then use this:
\begin{verbatim}
// only needed if you are not in the same cpp file
extern TAutoConsoleVariable<int32> CVarMyVar;
// Retrieve the MyVar value via Game Thread
int32 MyVar = CVarMyVar.GetValueOnGameThread();
\end{verbatim}
\end{itemize}
\subsection{Assertions}
Assertions can be used to ensure that specific conditions are fulfilled, before continue in the program flow. If the checks are not successful, the execution is halted. Assertions will only work when the \verb|DO_CHECK| macro is set (and not zero) during compiling.
There are different types of assertions:
\begin{itemize}
\item \textbf{check():} If the expression inside check() is false, the execution will be halted. The expression is only evaluated, when \verb|DO_CHECK| is set. If you need that the expression is always evaluated, then use verify().
\begin{verbatim}
check(OneProperty == 1);
verify(ImportantCall() != nullptr);
\end{verbatim}
\item \textbf{checkf():} Behaves like check(), but additional debug info is printed. verifyf() works analogous.
\item \textbf{checkNoEntry():} You can mark code path that should never be executed with this assertion. If it is still be called, the execution is halted.
\begin{verbatim}
switch(Property) {
case EEnum:Val1:
return 1;
default:
checkNoEntry();
}
\end{verbatim}
\item \textbf{unimplemented():} Use this assertions, on functions that are yet unimplemented or must be overridden to work properly.
\begin{verbatim}
void Function() {
//This func must be overriden to work
unimplemented();
}
\end{verbatim}
\end{itemize}
\subsection{Draw Debug Functions}
To use the following functions you need to include \verb|DrawDebugHelpers.h|.
\begin{itemize}
\item \textbf{DrawDebugPoint():} Draw a point in the world at a given location. You can choose Color and size of the point:
\begin{verbatim}
DrawDebugPoint(
GetWorld(),
MyLocation, //The location as FVector
20, //size of the point
FColor(255,0,0), //the color
false, //Not persistant
10.f //10s lifetime
);
\end{verbatim}
\item \textbf{DrawDebugLine():} Draw a line between to points in the world:
\begin{verbatim}
DrawDebugLine(
GetWorld(),
Start, //Start point
End, //End point
FColor(0,255,0), //Line Color
false, //Not persistant
-1, //Infinite lifetime
0,
10 //Line Thickness
);
\end{verbatim}
\end{itemize}
\doclicenseImage
\end{multicols*}
\end{document}