I made the move from an entirely blueprint project to predominantly c++ based project a little while ago, and figured I’d make a few tutorials on things I found easy in blueprint, but had to trawl through forums to get up and running in c++. Also figured I’d leave general forms of them here so it’s easy to copy paste, as I still find myself digging through old projects to find places I’ve done these before to copy the syntax.
Enums
Link to tutorial: Enums in UE4 c++ - YouTube
Cheat sheet syntax:
Declaring an Enum:
UENUM(BlueprintType)
enum EMyEnum
{
PRE_Value1 UMETA(DisplayName = "BlueprintName"),
PRE_Value2 UMETA(DisplayName = "BlueprintName2"),
PRE_Value3 UMETA(DisplayName = "BlueprintName3")
// etc. etc.
};
Getting the Enum type to get data from:
const UEnum* yourEnum = FindObject<UEnum>(ANY_PACKAGE, TEXT("EMyEnum"), true);
yourEnum->GetMaxEnumValue();
etc.
Structs
Link to tutorial: UE4 c++ UStruct syntax - YouTube
Cheat Sheet Syntax
Declaring a struct:
USTRUCT(BlueprintType)
struct FYourStruct
{
GENERATED_USTRUCT_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Struct")
Type Name;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Struct")
Type Name;
};
OnComponentOverlap and OnComponentHit
Link to tutorial: UE4 c++ OnComponentOverlap and OnComponentHit syntax - YouTube
Cheat Sheet Syntax:
Overlap Signature:
UFUNCTION()
void MyOverlapFunction(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
**Hit Signature: **
UFUNCTION()
void MyHitFunction(AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
Bind Overlap:
MyPrimitiveComponent->OnComponentBeginOverlap.AddDynamic(this, &AMyActor::MyFunction);
Bind Hit:
MyPrimitiveComponent->OnComponentHit.AddDynamic(this, &AMyActor::MyFunction);
Delay/Timer
Link to tutorial: UE4 c++ Delay/Timer syntax - YouTube
Cheat sheet syntax:
Declare timer handle:
FTimerHandle _loopTimerHandle;
How to set up the equivalent of a delay in c++ using the timer manager.
Copy paste syntax:
Declare timer handle:
FTimerHandle _loopTimerHandle;
Begin timer:
GetWorld()->GetTimerManager().SetTimer(_myTimerHandle, this, &AMyActor::MyFunctions, DelayDuration(as a float), false);
Event Dispatcher / Delegates
Link to tutorial: UE4 c++ Event Dispatchers syntax - YouTube
Cheat Sheet Syntax:
Delegate Type Declaration
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FYourDelegateType, VarType, VarName);
Delegate naming
UPROPERTY(BlueprintAssignable, Category = "EventDispatchers")
FYourDelegateType YourDelegateName;
Calling A Delegate
YourDelegateName.Broadcast(YourParameters);
Assigning/Binding to delegate
ActorWithDelegate->YourDelegateName.AddDynamic(this, &YourClass::YourFunction);
Blueprint friendly Interfaces in C++
Link to tutorial: UE4 Cpp Interface Setup - Part 1 - YouTube