Explore UnrealEngine in CPP(main) / Blueprint(co)
- New Cpp classes: Switch to
C++ Classes
, right click to create new cpp class. - Delete Cpp classes: Delete local
.cpp && .h
files, then delete binary files and restart editor (UE will rebuild the project). Then, the unwanted cpp classes are removed from the editor.
-
Reflection System in UnrealEngine →: By
#include "FileName.generated.h"
, You can now useUENUM(), UCLASS(), USTRUCT(), UFUNCTION(), UPROPERTY(), ...
to annotate different types and member variables in the header. -
Coding Standard →
-
Forward Declaration: The standard way to declare a complex class, which indicates to additionally include other header files, in the current header file is to use Forward Declaration, which intuitively tells the compiler "Currently I cannot give you the definition, but I promise I will give you later.". This is because, if we do not use forward declaration and do not include the extra header files, then the compiler will have no clue of what those types are, while if we do not use forward declaration and do include the extra header files, then it will introduce the hazard of circular dependency. In other word, using forward declaration is the only secure way to solve this situtation.
-
Game Flow: Despite different play mode (Editor Mode / Standalone Mode), a coarse game flow can be concluded as follow.
UWorld::BeginPlay
is first called which starts the gameplay and correctifies the state of game mode →.AGameMode::StartPlay
andAGameMode::StartMatch
is then called which spawns actors and triggers the actors'BeginPlay
. (For more details, please refer to →)- Therefore, always spawn actors in
BeginPlay
rather than the constructor, simply because during the constructor stage,UWorld
is probably not prepared.
- Therefore, always spawn actors in
- Physics: The majority API of Physics is defined in
UPrimitiveComponent
→.- Note that when simulating physics, UE4 always uses simple collision rather than complex collision.
- UMG: As several tutorials and suggestions found in the community, the recommended way to code with UMG in UE4 is to combine CPP and Blueprint. Followed by these typical suggestions [1] [2], the architecture can be concluded as
- Create the cpp class which inherits
UUserWidget
and define the class members and functions. Important functions includeNativeContruct()
,NativeTick(const FGeometry& MyGeometry, float InDeltaTime)
. - Create the blueprint in the editor which inherits the above cpp class. One trick here is that we'd better create the blueprint initially as a subclass of
UserWidget
as usual. After creation, change the parent of the blueprint inFile/Reparent blueprint
to the target cpp class. Otherwise, we really cannot edit the UI panel. Still, make sure that we manaully create the widgets in the blueprint editor with the same name as those of the class member defined in the parent cpp class. - To control the appearance of mouse cursor, set
APlayerController->bShowMouseCursor
and set controller input modeAPlayerController->SetInputMode(FInputModeDataBase)
to instantly affect the mouse controlability (otherwise an extra click is required to activate mouse cursor).
- Create the cpp class which inherits