Don’t be fooled. Unreal Engine C++ is not “normal C++”. The unreal header tool enforces strict rules about pointers and the Engine features a Garbage Collector and reference counting under the hood. You might encounter some crashes in shipping builds due to an object being GCed and you tried to access it, but this is usually how far it goes in terms of manual memory management.
Everything in this Section can easily be resolved by using Rider instead of VS 2022 + VA.
. to -> when you absolutely want a dot, which can be frustrating.TUniquePtr) and you should use them instead of the std:: . 🔗
MoveTemp is equivalent to std::move, but with a different name (ue::move or ue::Move would have been more intuitive imho).Component Handling: The API for handling components is inconsistent:
GetComponentByClass<UStaticMeshComponent>().AddComponentByClass(UStaticMeshComponent::StaticClass(), false, FTransform(), false), which includes redundant boolean parameters.GetComponentsByClass(UStaticMeshComponent::StaticClass()), replaced by a more complex method.Converting To/From String:
There is a free function ToString that converts some unreal types to FString, some others to const TCHAR*
There is a FString::FromInt function
There is a FString::SanitizeFloatfunction
FName and FText have a ToString member function, but only FText has a FromString
EnumToString<EResourceType>(EResourceType::Wood); // returns: Wood
UEnum::GetValueAsString<EResourceType>(EResourceType::Wood); // returns EResourceType::Wood
StaticEnum<EResourceType>()->GetValueAsString(EResourceType::Wood); // returns: EResourceType::Wood
FText has a EqualTo function, while FString calls it Equals while FName uses the == operator.
Inconsistent Logging Mechanisms: Logging to the console and the display uses different mechanisms:
UE_LOG macro, which includes log levels.GEngine->AddOnScreenDebugMessage, which does not support log levels. Additionally, the UE_LOG macro can be entirely removed by the compiler to save performance, but this is not the case for AddOnScreenDebugMessage.FMessageLog("Log_Category").Error(...)Unhelpful Error Messages: UHT Error messages are sometimes just bad or even confusing.
| Error: | Means: |
|---|---|
| WeaponEffects.h(10,2): Error C4430 : missing type specifier - int assumed. Note: C++ does not support default-int |
GENERATED_BODY() ^ |
#include "WeaponEffects.generated.h"is missing in the file. | | | |
Linker Errors: Due to Unreals custom build tooling the Linker errors often don’t help to find the actually issue.
Namespace Issues: The UCLASS and USTRUCT macros cannot be used within namespaces, limiting the organization of code. 🔗
Reflection System Compatibility: TOptional<> is not compatible with the reflection system, meaning it can't be used with anything related to Blueprint or UPROPERTY/UFUNCTION. 🔗