### Unreal Engine Command: FirstInstall Flag Source: https://unreal-garden.com/docs/command-line-arguments This flag is used in conjunction with `CultureForCooking`. When both are set, it directs the engine to write the specified culture from `CultureForCooking` into the `Internationalization` section of the engine's .ini file, typically for initial installation setups. ```APIDOC Command: -FirstInstall Type: flag Related: CultureForCooking Description: Based on the code, if CultureForCooking and FirstInstall are set, it writes the culture specified by CultureForCooking to the Internationalization part of the engine .ini file. ``` -------------------------------- ### Basic Usage of TOptional in Unreal Engine Source: https://unreal-garden.com/tutorials/toptional Provides fundamental examples of `TOptional` instantiation, assignment, value retrieval using `GetValue()`, and comparison, demonstrating its core functionalities. It also notes the `checkf` behavior of `GetValue()` and introduces `Get(DefaultValue)` as a safer alternative. ```C++ // After creation, Size.IsSet() returns false TOptional Size; // Assignment is standard, and after this, Size.IsSet() returns true Size = 16; // Get the current value with GetValue() UE_LOG(LogTemp, Verbose, TEXT("Size is: %d:"), Size.GetValue()); // == works as you'd expect, and will return false if IsSet() is false if (Size == 16) { // returns true } ``` -------------------------------- ### Basic UUserWidget C++ Subclass Example Source: https://unreal-garden.com/tutorials/ui-cpp-uuserwidget This example provides the header and implementation files for a minimal C++ subclass of UUserWidget, named UExampleWidget. It demonstrates the basic structure for creating an abstract C++ base class intended for Blueprint subclassing in Unreal Engine, including the override of NativeConstruct for initialization. ```C++ #pragma once #include "Blueprint/UserWidget.h" #include "ExampleWidget.generated.h" // We make the class abstract, as we don't want to create // instances of this, instead we want to create instances // of our UMG Blueprint subclass. UCLASS(Abstract) class UExampleWidget : public UUserWidget { GENERATED_BODY() protected: // Doing setup in the C++ constructor is not as // useful as using NativeConstruct. virtual void NativeConstruct() override; }; ``` ```C++ #include "ExampleWidget.h" void UExampleWidget::NativeConstruct() { Super::NativeConstruct(); // Here is where I typically bind delegates, // and set up default appearance } ``` -------------------------------- ### Unreal Engine Sparse Delegate Class Example (Dog.h) Source: https://unreal-garden.com/tutorials/delegates-advanced A C++ example demonstrating the declaration and usage of a sparse delegate within an Unreal Engine AActor class. It shows how to forward declare the owning class and define a one-parameter sparse delegate for infrequent events, optimizing memory for many instances of the object. ```C++ #pragma once #include "GameFramework/Actor.h" #include "Dog.generated.h" // Note you have to forward declare here, you *cannot* do it within the // delegate declaration class ADog; DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_OneParam(FOnDogWoofSignature, ADog, OnDogWoofDelegate, FString, WoofText); UCLASS() class ADog : public AActor { GENERATED_BODY() // We only very rarely need to subscribe to woofs // And we have a *lot* of dogs FOnDogWoofSignature OnDogWoofDelegate; }; ``` -------------------------------- ### Original UUserWidget Class Hierarchy Example Source: https://unreal-garden.com/tutorials/ui-best-practices Illustrates a typical, less optimized hierarchy where multiple UUserWidget subclasses directly inherit from UUserWidget, leading to potential code duplication for common functionalities and less centralized control. ```text UUserWidget ├ UBUIUWHealthBar ├ UBUIUWMenuPage │ └ UBUIUWMenuSettingsPage └ UBUIUWInventoryItem ``` -------------------------------- ### Unreal Engine CLI: Installed Source: https://unreal-garden.com/docs/command-line-arguments For development purposes, this flag makes the game behave as if it were a fully installed version, affecting paths and resource loading. It is the opposite of '-NotInstalled'. ```APIDOC Installed: Type: flag Description: For development purposes, run the game as if installed. Opposite: NotInstalled Source: Unreal Documentation ``` -------------------------------- ### Unreal Engine Command-Line Argument: InstallGE Source: https://unreal-garden.com/docs/command-line-arguments This flag instructs the Unreal Engine to add the game to the Windows Game Explorer. This feature was part of older Windows versions for managing installed games. ```APIDOC InstallGE: Type: flag Description: Add the game to the Game Explorer. ``` -------------------------------- ### Unreal Engine C++ Placeholder Text Example Source: https://unreal-garden.com/tutorials/industries-titan-localization An example of using `FText::FromString` in Unreal Engine C++ to set a text label. This method is highlighted as a common source of unlocalizable 'placeholder' text that often makes it into production, and should generally be avoided for player-facing text. ```C++ MyTextLabel->SetText(FText::FromString("Just Show This")); ``` -------------------------------- ### Unreal Engine UCLASS ExposedAsyncProxy Usage Examples Source: https://unreal-garden.com/docs/uclass Examples demonstrating how to use the ExposedAsyncProxy UCLASS specifier to expose a proxy object in async task nodes, including a basic meta usage and an abstract class example. ```C++ UCLASS(meta=(ExposedAsyncProxy="abc")) ``` ```C++ UCLASS(Abstract, meta = (ExposedAsyncProxy = AsyncAction)) class GAMEPLAYABILITIES_API UAbilityAsync : public UBlueprintAsyncActionBase ``` -------------------------------- ### Unreal Engine Command: CultureForCooking String Source: https://unreal-garden.com/docs/command-line-arguments Specifies the language to be used during the cooking process in Unreal Engine. This argument functions similarly to `Culture` but can be combined with the `FirstInstall` flag for initial setup scenarios. ```APIDOC Command: -CultureForCooking="" Type: string Related: FirstInstall Description: Does the same as Culture but can has the option to work with FirstInstall. Set language to be used for cooking. ``` -------------------------------- ### Example Usage of BlueprintGetter and BlueprintSetter Source: https://unreal-garden.com/docs/uproperty Illustrates the combined use of `BlueprintGetter` and `BlueprintSetter` with a boolean property. It shows how to define the property and its corresponding `UFUNCTION`s for custom read and write access from Blueprints, ensuring proper function signatures. ```C++ UPROPERTY(EditAnywhere, BlueprintGetter = IsPassEnabled, BlueprintSetter = SetPassEnabled ) bool bEnabled = true; UFUNCTION(BlueprintGetter) bool IsPassEnabled() const; UFUNCTION(BlueprintSetter) void SetPassEnabled(bool bSetEnabledTo = true); ``` -------------------------------- ### Example INI Override for AZERTY Keybindings Source: https://unreal-garden.com/tutorials/ue4-localized-azerty-keybind This `.ini` file example illustrates how to override default WASD movement bindings to ZQSD for an AZERTY keyboard layout. The `-` prefix removes an existing mapping, and `+` adds a new one, allowing for specific key reassignments. ```INI [/Script/Engine.InputSettings] -ActionMappings=(ActionName="PanLeft",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=A) +ActionMappings=(ActionName="PanLeft",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Q) -ActionMappings=(ActionName="PanUp",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=W) +ActionMappings=(ActionName="PanUp",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Z) ``` -------------------------------- ### Unreal Engine Command: LogTimesSinceStart Flag Source: https://unreal-garden.com/docs/command-line-arguments Displays log timestamps as the elapsed time since the engine started. This flag is mutually exclusive with other log time display options. ```APIDOC Command: -LogTimesSinceStart Type: flag Incompatible with: LogTimes, UTCLogTimes, LocalLogTimes, LogTimeCode Opposite: NoLogTimes Description: Print log timestamps as time elapsed since engine start. ``` -------------------------------- ### AngelScript Example: Object Instantiation and Handles Source: https://unreal-garden.com/tutorials/scripting-languages This AngelScript snippet illustrates how objects are declared and instantiated. It specifically shows the use of object handles (`@`), which are a core feature of AngelScript, providing a safe alternative to raw pointers for object references. ```AngelScript void DoSomething() { SomeObject myObj; // AngelScript SomeObject@ myObjHandle = null; @myObjHandle = SomeObject(); } ``` -------------------------------- ### Unreal Engine CLI: NotInstalled Source: https://unreal-garden.com/docs/command-line-arguments This flag is the opposite of '-Installed', implying the game is not treated as a fully installed version. This can affect how the engine locates and loads assets. ```APIDOC NotInstalled: Type: flag Description: Treats the game as if it is not installed. Opposite: Installed ``` -------------------------------- ### Unreal Engine Function Reference with Advanced Options Example Source: https://unreal-garden.com/docs/uproperty An advanced C++ example demonstrating the use of `FunctionReference` in conjunction with `AllowFunctionLibraries`, `PrototypeFunction`, and `DefaultBindingName` to create a highly customized function picker in the Unreal Editor. It uses `FMemberReference` to store the selected function. ```C++ UPROPERTY(EditAnywhere, meta=(FunctionReference, AllowFunctionLibraries, PrototypeFunction="/Script/Bruno.DiceFunctionLibrary.Prototype_DiceCheck", DefaultBindingName="DiceCheck"), DisplayName="Dice Check") FMemberReference DiceCheck; ``` -------------------------------- ### Call C++ Function with TFunctionRef Lambda Source: https://unreal-garden.com/tutorials/tfunctionref This example shows how to call the `SetupContents` function, passing a C++ lambda expression directly as the argument for the `TFunctionRef` parameter. The lambda `[](UInternalObject* Thing){ ... }` provides the specific initialization logic that `SetupContents` will execute for each internal object. This demonstrates the practical usage of `TFunctionRef` for injecting custom behavior. ```C++ SetupContents(MyStuff, [](UInternalObject* Thing) { // Do something with Thing to initialize it }); ``` -------------------------------- ### Unreal Engine UPROPERTY AllowedTypes Usage Examples Source: https://unreal-garden.com/docs/uproperty Illustrates practical applications of the `AllowedTypes` meta tag on `FPrimaryAssetId` and `TMap` properties. These examples show how to restrict the types of primary assets that can be selected in the editor using a custom asset type. ```C++ UPROPERTY(meta = (AllowedTypes = "FancyAssetName")) FPrimaryAssetId FancyAsset; ``` ```C++ /** Affects any primary asset ID's in the TMap */ UPROPERTY(meta = (AllowedTypes = "FancyAssetName")) TMap FancyAssetMap; ``` -------------------------------- ### Unreal Engine C++ Plugin Compilation Errors Source: https://unreal-garden.com/tutorials/how-to-install-plugin These are common compilation and linking errors that occur in Unreal Engine C++ projects when a manually installed plugin's module is not correctly referenced. The first error indicates a missing header file, while the second points to an unresolved symbol, both typically resolved by adding the plugin's module to the project's build dependencies. ```C++ Cannot open include file: 'MyPlugin.h': No such file or directory ``` ```C++ unresolved external symbol "__declspec(dllimport) public: __cdecl UMyPlugin::UMyPlugin(class FObjectInitializer const &)" (__imp_??0UMyPlugin@@QEAA@AEBVFObjectInitializer@@@Z) referenced in function ... ``` -------------------------------- ### Get or Create Widget Instance from Pool (C++) Source: https://unreal-garden.com/tutorials/userwidget-pool This snippet demonstrates how to use `FUserWidgetPool::GetOrCreateInstance` to retrieve an existing widget from the pool or create a new one if none are available. It shows how to specify the widget class type, which can be a `UUserWidget` or a more specific subclass. ```C++ // This type does not have to be UUserWidget, it can be the exact subclass of UUserWidget TSubclassOf WidgetClass; // ... this could be set up in the header UUserWidget* Widget = WidgetPool.GetOrCreateInstance(WidgetClass); ``` -------------------------------- ### Unreal Engine UPROPERTY Replicated Specifier and Network Replication Setup Source: https://unreal-garden.com/docs/uproperty Explains how to mark a `UPROPERTY` for network replication using the `Replicated` specifier in Unreal Engine. Includes the necessary `GetLifetimeReplicatedProps` function implementation in the `.cpp` file to define which properties should be replicated. ```C++ UPROPERTY(Replicated) ``` ```C++ #pragma once # include "MyReplicatedThing.generated.h" // MyReplicatedThing.h UCLASS() class UMyReplicatedThing { GENERATED_BODY() protected: UPROPERTY(Replicated) int32 Count; }; ``` ```C++ // MyReplicatedThing.cpp #include "MyReplicatedThing.h" #include "Net/UnrealNetwork.h" void UMyReplicatedThing::GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const { Super::GetLifetimeReplicatedProps(OutLifetimeProps); DOREPLIFETIME(UMyReplicatedThing, Count); } ``` -------------------------------- ### Example CSV Stringtable File Source: https://unreal-garden.com/tutorials/byg-localization Demonstrates the structure of the `loc_en.csv` file used by the BYG Localization plugin, including `Key`, `SourceString`, `Comment`, `English`, and `Status` columns for defining localized text entries. This file serves as the authoritative source for strings. ```CSV Key,SourceString,Comment,English,Status Hello_World,"Hello world, how are you?",General greeting.,, Goodbye_World,"See you later!",Shown when quitting the game.,,, ``` -------------------------------- ### Unreal Engine C++: Creating Localizable FText Strings Source: https://unreal-garden.com/tutorials/ui-localization This C++ example illustrates the use of LOCTEXT_NAMESPACE with LOCTEXT to define a localized text string within a specific namespace. It demonstrates the standard pattern for creating localizable FText variables in C++ code, which is crucial for supporting multiple languages in Unreal Engine applications. ```C++ // Top of File #define LOCTEXT_NAMESPACE "FarmGame" FText TestHUDText = LOCTEXT("Your Key", "Your Text"); #undef LOCTEXT_NAMESPACE // Bottom of File ``` -------------------------------- ### Example Content Browser Filter for Texture Group Source: https://unreal-garden.com/tutorials/content-browser-filters Demonstrates a practical application of the Content Browser query syntax to filter assets by their 'TextureGroup' metadata attribute, specifically for assets belonging to the 'Default' group. ```Unreal Content Browser Query TextureGroup==Default ``` -------------------------------- ### Example Usage of IncludeAssetBundles with TSoftPtrs Source: https://unreal-garden.com/docs/uproperty Demonstrates how `IncludeAssetBundles` is applied to `TSoftClassPtr` and `TSoftObjectPtr` within `UCLASS` definitions. This ensures that nested asset references are properly bundled, allowing a container's properties to be included in a primary asset's `AssetBundleData`. ```C++ UCLASS() class UMyContainer : public UObject { GENERATED_BODY() UPROPERTY(EditDefaultsOnly, meta=(AssetBundles="Client")) TSoftClassPtr Something; } UCLASS() class UMyPrimaryAsset : public UPrimaryDataAsset { // Without meta=(IncludeAssetBundles), the properties within UMyContainer // would not be added to this asset's AssetBundleData UPROPERTY(EditDefaultsOnly, meta=(IncludeAssetBundles)) TSoftObjectPtr Container; } ``` -------------------------------- ### Define C++ Class for Unreal UI Material Example Source: https://unreal-garden.com/tutorials/ui-dynamic-materials This C++ header file defines the `UMaterialExample` class, which inherits from `UUserWidget`. It declares properties necessary for handling UI materials, including an `UImage` widget reference, a base `UMaterialInterface`, a dynamic `UMaterialInstanceDynamic` instance, and an `UTexture2D` for parameterization. The `BindWidget` meta-property is used to link the `IconImage` to a UMG widget. ```C++ #pragma once #include "MaterialExample.generated.h" UCLASS(Abstract) class UMaterialExample : public UUserWidget { GENERATED_BODY() public: virtual void NativeConstruct() override; // We need an Image widget in our Blueprint class named "IconImage" UPROPERTY(BlueprintReadOnly, meta = (BindWidget)) TObjectPtr IconImage = nullptr; // Our base material that will be the template for our material instance UPROPERTY(EditDefaultsOnly) TObjectPtr IconMaterial = nullptr; // Our actual material instance TObjectPtr IconMaterialInstance = nullptr; // A texture we'll set as a parameter to our dynamic material instance UPROPERTY(EditDefaultsOnly) TObjectPtr IconTexture = nullptr; }; ``` -------------------------------- ### Unreal Engine CLI: WaitForDebugger Source: https://unreal-garden.com/docs/command-line-arguments Causes Unreal Engine to pause execution until a debugger is successfully connected, allowing for debugging setup before the application fully starts. ```APIDOC WaitForDebugger: Type: flag Description: Causes Unreal to wait for a debugger to be connected before continuing execution. ``` -------------------------------- ### Accessing Unreal Subsystems from C++ Source: https://unreal-garden.com/tutorials/subsystem-singleton Demonstrates how to retrieve instances of Unreal Engine subsystems from `UGameInstance` and `ULocalPlayer` using the `GetSubsystem()` template method. This is the standard way to access globally available subsystem instances. ```cpp UGameInstance* GameInstance = ...; UMyGameSubsystem* MySubsystem = GameInstance->GetSubsystem(); ULocalPlayer* LocalPlayer = ...; UMyPlayerSubsystem* MySubsystem = LocalPlayer->GetSubsystem(); ``` -------------------------------- ### SkookumScript Concurrency with Race Keyword Source: https://unreal-garden.com/tutorials/scripting-languages This SkookumScript example illustrates the language's built-in concurrency features using the 'race' keyword. It shows how to execute multiple commands (like 'person._walk' and 'car._drive') simultaneously and proceed once the first one completes, automatically cancelling any remaining commands. ```SkookumScript // Person and car both start at same time. // Next line is run after whichever one completes first // and any remaining commands are cancelled. race [ person._walk car._drive ] println("Completed") ``` -------------------------------- ### PreferIntel Command-Line Argument Source: https://unreal-garden.com/docs/command-line-arguments Documents the `PreferIntel` command-line flag for Unreal Engine, used to set Intel as the preferred adapter vendor for graphics rendering across Windows D3D12, D3D11, and Vulkan RHIs. ```APIDOC PreferIntel: Type: flag Related: PreferAMD, PreferNVidia, PreferMS Notes: Part of the Windows D3D12, D3D11 and Vulkan Render Hardware Interfaces, this lets you set a preferred adapter vendor. Useful if you've optimised for one over another, and the user has multiple installed. ``` -------------------------------- ### Implement ADog Actor Behavior and Health Widget Setup Source: https://unreal-garden.com/tutorials/ui-in-world This C++ file implements the `ADog` actor's constructor, `BeginPlay`, and `Tick` methods. The constructor initializes the `UWidgetComponent` and attaches it. `BeginPlay` casts the widget to `UHealthBar` and sets its owner, then initializes random health and movement. `Tick` updates the actor's location and animates the health value for demonstration. ```C++ #include "Dog.h" #include "Components/WidgetComponent.h" #include "HealthBar.h" ADog::ADog(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { PrimaryActorTick.bCanEverTick = true; if (RootComponent == nullptr) { RootComponent = ObjectInitializer.CreateDefaultSubobject(this, TEXT("Root")); } HealthWidgetComp = ObjectInitializer.CreateDefaultSubobject(this, TEXT("HealthBar")); HealthWidgetComp->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform); Health = MaxHealth; } void ADog::BeginPlay() { Super::BeginPlay(); UHealthBar* HealthBar = Cast(HealthWidgetComp->GetUserWidgetObject()); HealthBar->SetOwnerDog(this); // Make sure every dog starts with different health Health = FMath::RandRange(0.0f, MaxHealth); HealthTweenDirection = FMath::RandBool() ? 1 : -1; // Move in a random direction at a random speed const float DirRads = FMath::RandRange(0.0f, 2 * PI); MovementVelocity = FVector(FMath::Cos(DirRads), FMath::Sin(DirRads), 0) * 10.0f; // Face that way too RootComponent->SetWorldRotation(FRotator::MakeFromEuler(FVector(0, 0, DirRads / PI * 180 - 90))); } void ADog::Tick(float DeltaTime) { Super::Tick(DeltaTime); SetActorLocation(GetActorLocation() + MovementVelocity * DeltaTime); // Bounce health between min and max to show off health bar static const float TweenSpeed = 10.0f; Health = FMath::Clamp(Health + DeltaTime * HealthTweenDirection * TweenSpeed, 0, MaxHealth); if ((Health == MaxHealth && HealthTweenDirection == 1) || (Health == 0 && HealthTweenDirection == -1)) { HealthTweenDirection *= -1; } } ``` -------------------------------- ### Implement Main Menu Widget Operations in ABUIHUD Class Source: https://unreal-garden.com/tutorials/ui-setup This C++ source file implements the `ShowMainMenu` and `HideMainMenu` functions of the `ABUIHUD` class. `ShowMainMenu` creates an instance of the `MainMenuClass` widget and adds it to the viewport, while `HideMainMenu` removes the widget from the viewport and clears its reference. It depends on `PlayerController` and `UserWidget` classes for widget ownership and manipulation. ```C++ #include "BUIHUD.h" #include "GameFramework/PlayerController.h" #include "Blueprint/UserWidget.h" #include "Kismet/GameplayStatics.h" void ABUIHUD::ShowMainMenu() { // Make widget owned by our PlayerController APlayerController* PC = Cast(GetOwner()); MainMenu = CreateWidget(PC, MainMenuClass); MainMenu->AddToViewport(); } void ABUIHUD::HideMainMenu() { if (MainMenu) { MainMenu->RemoveFromViewport(); MainMenu = nullptr; } } ``` -------------------------------- ### Unreal Project-wide Class Prefix Naming Convention Source: https://unreal-garden.com/tutorials/ui-best-practices Recommends adding a unique project or company-wide prefix to all in-house developed C++ classes to distinguish them from Unreal's built-in classes and prevent naming clashes. For example, if working at Benui Co., classes might be prefixed with `BUI`. ```C++ // Example C++ class names with project prefix class ABUIDog; // Actor class for a dog class ABUIBall; // Actor class for a ball // Differentiating Unreal built-in vs. custom classes class UButton; // Unreal's built-in UButton widget class UBUIButton; // In-house custom UButton subclass ``` -------------------------------- ### UPROPERTY with EditInline and TObjectPtr Example Source: https://unreal-garden.com/docs/uproperty Demonstrates the application of the deprecated `EditInline` meta specifier in conjunction with `EditAnywhere` and a `TObjectPtr` property. This shows how `EditInline` would typically be used for an object reference within the Unreal Editor's property inspector. ```cpp UPROPERTY(EditAnywhere, meta=(EditInline)) TObjectPtr Dog; ``` -------------------------------- ### Define ABUIHUD Class for UI Management in Unreal Engine Source: https://unreal-garden.com/tutorials/ui-setup This C++ header file defines the `ABUIHUD` class, inheriting from `AHUD`. It declares `BlueprintCallable` functions `ShowMainMenu` and `HideMainMenu` for controlling a main menu widget, and properties `MainMenuClass` (to specify the widget blueprint) and `MainMenu` (to hold a reference to the created widget). ```C++ #pragma once #include "GameFramework/HUD.h" #include "BUIHUD.generated.h" UCLASS(Abstract) class ABUIHUD : public AHUD { GENERATED_BODY() public: // Make BlueprintCallable for testing UFUNCTION(BlueprintCallable) void ShowMainMenu(); UFUNCTION(BlueprintCallable) void HideMainMenu(); protected: UPROPERTY(EditDefaultsOnly) TSubclassOf MainMenuClass; // Keep a pointer to be able to hide it UPROPERTY() TObjectPtr MainMenu; }; ``` -------------------------------- ### Unreal Engine UCLASS SparseClassDataTypes Usage Example Source: https://unreal-garden.com/docs/uclass Example demonstrating the SparseClassDataTypes UCLASS specifier, which leverages the Sparse Class Data system to save memory. ```C++ UCLASS(SparseClassDataTypes="abc") ``` -------------------------------- ### Unreal Engine UCLASS HasDedicatedAsyncNode Usage Example Source: https://unreal-garden.com/docs/uclass Example demonstrating the HasDedicatedAsyncNode UCLASS specifier, which, when present, prevents the editor from creating an async node in the graph. ```C++ UCLASS(meta=(HasDedicatedAsyncNode)) ``` -------------------------------- ### Unreal Engine UCLASS Within Usage Examples Source: https://unreal-garden.com/docs/uclass Examples demonstrating the Within UCLASS specifier, which enforces an ownership hierarchy, requiring an instance of the specified OuterClassName as its Outer Object. ```C++ UCLASS(Within="abc") ``` ```C++ UCLASS(Within=PlayerController) class ENGINE_API UPlayerInput : public UObject ``` -------------------------------- ### Slate Widget Base Classes for Subclassing Source: https://unreal-garden.com/tutorials/ui-cpp-slate This API documentation outlines the primary base classes available for creating new Slate widgets from scratch. It provides options for different widget complexities and functionalities, guiding developers on which class to subclass based on their needs. ```APIDOC Available Base Classes for Slate Widgets: - SCompoundWidget: Most commonly used parent class for composite widgets that contain other widgets. - SLeafWidget: Suitable for simple widgets that do not contain children and handle their own drawing. - SPanel: Designed for widgets that manage and arrange child widgets, such as layout containers. ``` -------------------------------- ### Call ShowMainMenu Function from C++ in Unreal Engine Source: https://unreal-garden.com/tutorials/ui-setup This C++ snippet demonstrates how to retrieve the `ABUIHUD` instance from the current `PlayerController` and then call its `ShowMainMenu` function. This is a common pattern for interacting with HUD-managed UI elements from game logic or other C++ classes within Unreal Engine. ```C++ APlayerController* PC = UGameplayStatics::GetPlayerController(GetWorld()); ABUIHUD* HUD = PC->GetHUD(); HUD->ShowMainMenu(); ``` -------------------------------- ### Unreal Engine UCLASS DependsOn Usage Example Source: https://unreal-garden.com/docs/uclass Example demonstrating the DependsOn UCLASS specifier, used to declare compilation dependencies on other classes, especially when using structs or enums from them. ```C++ UCLASS(DependsOn="abc") ``` -------------------------------- ### Unreal Engine UCLASS MinimalAPI Usage Examples Source: https://unreal-garden.com/docs/uclass Examples demonstrating the MinimalAPI UCLASS specifier, which allows a class to be cast to outside its module but restricts direct function calls, improving compile times. ```C++ UCLASS(MinimalAPI) ``` ```C++ // For example we have a class in MyGameplayModule that we want to be able to cast to elsewhere // Note we do *not* add MYGAMEPLAYMODULE_API UCLASS(MinimalAPI) class ASomeGameplayClass : public AActor ``` -------------------------------- ### Implement UExampleOverlay Class Methods in C++ Source: https://unreal-garden.com/tutorials/ui-cpp-uwidget This C++ source file provides the implementation for the `UExampleOverlay` class methods. It shows the override for `RebuildWidget()`, which calls the superclass's implementation and includes a placeholder for custom slot processing. Additionally, it implements `GetPaletteCategory()` to define the widget's display name in the Unreal Editor. ```C++ #define LOCTEXT_NAMESPACE "ExampleUMG" TSharedRef UExampleOverlay::RebuildWidget() { auto Result = Super::RebuildWidget(); for (UPanelSlot* InSlot : Slots) { // Do something custom } return Result; } #if WITH_EDITOR const FText UExampleOverlay::GetPaletteCategory() { return LOCTEXT("ExampleUI", "ExampleOverlay"); } #endif ``` -------------------------------- ### Define Inventory Panel Widget Class (C++ Header) Source: https://unreal-garden.com/tutorials/ui-synchronize-properties This C++ header file defines the `UInventoryPanelWidget` class, a subclass of `UUserWidget`. It declares properties for configuring the inventory panel, such as label text, the class of the item widget, and the grid dimensions (columns and rows). It also declares the override for the `SynchronizeProperties` method, which is crucial for editor-time updates. ```C++ #pragma once #include "InventoryPanelWidget.generated.h" UCLASS(Blueprintable, Abstract) class UInventoryPanelWidget : public UUserWidget { GENERATED_BODY() public: virtual void SynchronizeProperties() override; UPROPERTY(EditAnywhere, Category = "Inventory Panel") FText LabelText; UPROPERTY(EditAnywhere, Category = "Inventory Panel") TSubclassOf ItemWidgetClass = nullptr; UPROPERTY(EditAnywhere, Category = "Inventory Panel") int32 Columns = 4; UPROPERTY(EditAnywhere, Category = "Inventory Panel") int32 Rows = 3; UPROPERTY(BlueprintReadOnly, Category = "Inventory Panel", meta=(BindWidget)) TObjectPtr Label; UPROPERTY(BlueprintReadOnly, Category = "Inventory Panel", meta=(BindWidget)) TObjectPtr Grid; }; ``` -------------------------------- ### AllowSoftwareRendering Command-Line Argument Source: https://unreal-garden.com/docs/command-line-arguments Documents the `AllowSoftwareRendering` command-line flag for Unreal Engine, which enables fallback to software rendering in D3D11 and D3D12 RHIs. ```APIDOC AllowSoftwareRendering: Type: flag Description: In the D3D11 and D3D12 RHI, setting this allows it to fall back to software rendering. By default it seems this is disabled. ``` -------------------------------- ### Unreal Engine CLI: InstallFW Source: https://unreal-garden.com/docs/command-line-arguments Controls whether the Windows firewall integration should be performed, potentially prompting the user for firewall permissions. It is the opposite of '-UninstallFW'. ```APIDOC InstallFW: Type: flag Description: Set whether the handling of the firewall integration should be performed. Opposite: UninstallFW Source: Unreal Documentation ``` -------------------------------- ### Define UI Data Structure and Populator in C++ Source: https://unreal-garden.com/tutorials/ui-cpp-uuserwidget This C++ header defines `FUIPlantInfo`, a USTRUCT designed to hold UI-specific plant data such as short name and icon, ensuring only necessary properties are exposed. It also introduces `UIDataPopulator`, a UCLASS with a static method `GetPlantInfo` intended to populate this struct, demonstrating the separation of data logic from visual presentation in Unreal Engine UI development. ```C++ // Only contains properties that we are *sure* are needed in the UI USTRUCT(BlueprintType) struct FUIPlantInfo { GENERATED_BODY() UPROPERTY(BlueprintReadOnly, Category="Plant") FText ShortName; UPROPERTY(BlueprintReadOnly, Category="Plant") TObjectPtr Icon; }; UCLASS() class UIDataPopulator { GENERATED_BODY() public: // Populates a struct with all the info about the given plant. static void UIDataPopulator::GetPlantInfo(EPlantType Type, struct FUIPlantInfo& PlantInfo); }; ``` -------------------------------- ### UBUIAnimalCompass Implementation (C++) Source: https://unreal-garden.com/tutorials/userwidget-pool This C++ source file provides the implementation for `UBUIAnimalCompass`. It demonstrates how `NativeTick` can be used to get new widget instances from the pool (shown as pseudo-code for finding animals) and, crucially, how `ReleaseSlateResources` is overridden to call `WidgetPool.ReleaseAllSlateResources()` to prevent memory leaks, as per Unreal Engine's recommendations for proper Slate resource cleanup. ```C++ void UBUIAnimalCompass::NativeTick(const FGeometry& MyGeometry, float InDeltaTime) override { // Pseudo-code time... // Find all animals in the world // If they should be shown on-screen, create one WidgetPool.GetOrCreateInstance(WidgetClass); } void UBUIAnimalCompass::ReleaseSlateResources(bool bReleaseChildren) { WidgetPool.ReleaseAllSlateResources(); Super::ReleaseSlateResources(bReleaseChildren); } ``` -------------------------------- ### Example Usage of Pluralization Function in C++ Source: https://unreal-garden.com/tutorials/pluralizing-names A C++ example demonstrating how to use the `UMyGameplayStatics::GetIngredientName` function to obtain a pluralized ingredient name. It then shows how to format a complete sentence using `FText::Format` and set it to a UI label, combining the pluralized item name with other dynamic text. ```C++ struct FLootDrop { FString Ingredient; int32 Count; }; FLootDrop Loot { "Strawberry", 3 }; FText PluralizedIngredientName = UMyGameplayStatics::GetIngredientName(Loot.Ingredient, Loot.Count); FFormatNamedArguments Args; Args.Add("Ingredient", PluralizedIngredientName); Args.Add("Count", Loot.Count); FText LootText = FText::Format(FText::FromStringTable("MyTable", "Drop_Result"), Args)); // LootDropLabel now shows 'You found 3 strawberries!' LootDropLabel.SetText(LootText); ``` -------------------------------- ### Unreal UI Architecture: C++ for Logic, Blueprints for Visuals Source: https://unreal-garden.com/tutorials/ui-best-practices This section advocates for writing UI logic in C++ for performance, maintainability, and easier version control, while using Blueprint subclasses primarily for visual layout in UMG. It highlights the benefits of C++ over Blueprint for complex systems and team collaboration, and mentions the use of `meta=(Bindwidget)` for C++ to Blueprint interaction. ```C++ // Example of UPROPERTY with Bindwidget specifier for C++ to Blueprint binding UPROPERTY(meta=(Bindwidget)) class UButton* MyButton; ``` -------------------------------- ### Subclassing UBUIUWButton for Specific UI Elements (UBUIUWShopItemButton) Source: https://unreal-garden.com/tutorials/ui-best-practices Illustrates how to extend `UBUIUWButton` to create specialized UI elements, such as `UBUIUWShopItemButton`. This class adds specific properties like `PriceLabel` and `InventorySlotImage` for a shop item, while inheriting and retaining all the standard button functionality defined in `UBUIUWButton`, demonstrating the power of reusability and extensibility. ```cpp UCLASS() class UBUIUWShopItemButton : public UBUIUWButton { public: protected: UPROPERTY(meta=(BindWidgetOptional)) TObjectPtr PriceLabel; UPROPERTY(meta=(BindWidgetOptional)) TObjectPtr InventorySlotImage; }; ``` -------------------------------- ### Example UI StringTable CSV Structure Source: https://unreal-garden.com/tutorials/stringtable-cpp This CSV file (`UIStringTable.csv`) defines localized strings for an Unreal Engine project. Each row includes a unique `Key`, the `SourceString` (which can be multi-line and contain commas if quoted), and an optional `Comment` for context. This format allows Unreal Engine to load and manage localized text assets. ```CSV Key,SourceString,Comment HelloWorld,"Hello there, and welcome to the game!",Welcome message QuitGameLabel,"Quit the Game", LongDescription,"Welcome to the thing. Here's multi-line text.", ButtonLabel,"Click me", ``` -------------------------------- ### Unreal Engine Command-Line Argument: InstallFW Source: https://unreal-garden.com/docs/command-line-arguments This flag controls whether the Unreal Engine should handle firewall integration. Setting this argument enables or disables the automatic configuration of firewall rules by the engine. ```APIDOC InstallFW: Type: flag Description: Set whether the handling of the firewall integration should be performed. ``` -------------------------------- ### Unreal Engine Command-Line Argument: Benchmark Source: https://unreal-garden.com/docs/command-line-arguments Documents the `Benchmark` command-line argument, a flag that runs the game at a fixed step, ensuring each frame is processed without skipping. This is particularly useful when combined with `DUMPMOVIE` options. ```APIDOC Argument: Benchmark Type: flag Description: Run game at fixed-step in order to process each frame without skipping any frames. This is useful in conjunction with DUMPMOVIE options. ``` -------------------------------- ### Verse Tuple Definition and Element Access Source: https://unreal-garden.com/tutorials/what-is-verse Demonstrates how Verse defines and accesses elements within tuples, which function similarly to arrays in C++. Elements are accessed by index starting from 0. ```Verse ages := (23,49) ages[0]; // returns 23 ``` ```C++ int ages[] = {23, 49}; ages[0]; // returns 23 ``` -------------------------------- ### Unreal Engine UMG Naive List Panel Implementation Source: https://unreal-garden.com/tutorials/listview Implements the `NativeConstruct` method for `UBUIInventoryPanelNaive`. This code demonstrates the 'naive' approach to populating a list: it iterates through an imaginary inventory, creates a new `UBUIInventoryEntry` widget for each item, initializes it, and then adds it directly to a `UVerticalBox`. This method can be inefficient for large lists due to excessive widget creation. ```C++ #include "BUIInventoryPanelNaive.h" #include "Components/VerticalBox.h" void UBUIInventoryPanelNaive::NativeConstruct() { Super::NativeConstruct(); // Imagine we have an inventory class that provides us with the following: TArray Inventory; for (UBUIInventoryItem* Item : Inventory) { // Instantiate the widget UBUIInventoryEntry* Entry = CreateWidget(this, EntryClass); // Set up its contents Entry->InitializeFromInventoryItem(Item); // Add it to the list EntriesVerticalBox->AddChildToVerticalBox(Entry); } } ``` -------------------------------- ### Define UExampleOverlay Class Header in C++ Source: https://unreal-garden.com/tutorials/ui-cpp-uwidget This C++ header file defines `UExampleOverlay`, a custom UMG widget that subclasses `UOverlay`. It declares the `RebuildWidget()` override, which is essential for custom UI construction, and `GetPaletteCategory()` for proper integration and display within the Unreal Editor's widget palette. ```C++ UCLASS() class UExampleOverlay : public UOverlay { GENERATED_BODY() public: #if WITH_EDITOR virtual const FText GetPaletteCategory() override; #endif protected: // UWidget interface virtual TSharedRef RebuildWidget() override; // End of UWidget interface }; ``` -------------------------------- ### Disable Native Tick for UCLASS Source: https://unreal-garden.com/docs/uclass This specifier is primarily used on UUserWidget to disable its native tick functionality. The second code block shows an example of its usage in the UUserWidget class definition. ```cpp UCLASS(meta=(DisableNativeTick)) ``` ```cpp UCLASS(Abstract, editinlinenew, BlueprintType, Blueprintable, meta=( DontUseGenericSpawnObject="True", DisableNativeTick) ) class UMG_API UUserWidget : public UWidget, public INamedSlotInterface ``` -------------------------------- ### Implement Widescreen UI Panel Logic (C++) Source: https://unreal-garden.com/tutorials/ultrawide-ui This C++ source file implements the `UBYGUWWidescreenPanel` class. It initializes the panel, subscribes to game settings changes, and updates the `WidescreenRatioSizeBox` to apply or clear the maximum aspect ratio based on user preferences for ultrawide UI clamping. ```C++ // Copyright Brace Yourself Games. All Rights Reserved. #include "BYGUWWidescreenPanel.h" #include "Titan/Core/BYGGameUserSettings.h" #include "Components/SizeBox.h" #include "Titan/Util/BYGGameplayStatics.h" void UBYGUWWidescreenPanel::NativeConstruct() { Super::NativeConstruct(); if (UBYGGameUserSettings* GameSettings = UBYGGameplayStatics::GetBYGGameUserSettings()) { GameSettings->OnSettingsChangedDelegate.AddUniqueDynamic(this, &UBYGUWWidescreenPanel::OnSettingsChanged); GameSettings->OnSettingsAppliedDelegate.AddUniqueDynamic(this, &UBYGUWWidescreenPanel::OnSettingsChanged); } UpdateWidescreenRatioSizeBox(); } void UBYGUWWidescreenPanel::OnSettingsChanged() { UpdateWidescreenRatioSizeBox(); } void UBYGUWWidescreenPanel::UpdateWidescreenRatioSizeBox() { if (UBYGGameUserSettings* GameSettings = UBYGGameplayStatics::GetBYGGameUserSettings()) { if (GameSettings->UIWidescreenClampEnabled.GetCurrentValue()) { const FIntVector2D Vec = GameSettings->UIWidescreenClampRatioVec.GetCurrentValue(); WidescreenRatioSizeBox->SetMaxAspectRatio(Vec.X / (float)Vec.Y); } else { WidescreenRatioSizeBox->ClearMaxAspectRatio(); } } } ```