top of page

UE5 C++ Intermediate - Advanced Concepts



UPROPERTY() macro

UPROPERTY() is a macro used in Unreal Engine’s C++ codebase to define and expose class member variables to the engine's reflection system. It allows those variables to be:

  • Editable and visible in the Unreal Editor

  • Accessible and modifiable in Blueprints

  • Replicated across the network in multiplayer scenarios

  • Serialized when saving or loading objects

  • Easily configured with a variety of attributes and specifiers

It enables designers and developers to control how variables interact with Unreal’s tools like the Blueprint Editor, Property Window, Serialization system, and more.


UPROPERTY() Specifiers

There are several specifiers available for UPROPERTY() that control how the property behaves within the engine.

  1. EditAnywhere, EditDefaultsOnly, EditInstanceOnly

    • EditAnywhere: The property can be edited anywhere, including in the Blueprint’s default and instance properties.

    • EditDefaultsOnly: The property can only be edited in the Blueprint’s defaults, not at runtime.

    • EditInstanceOnly: The property can only be edited when an instance of the Blueprint is placed in the level.

  2. BlueprintReadWrite, BlueprintReadOnly

    • BlueprintReadWrite: The property is readable and writable in Blueprints, meaning you can get and set its value.

    • BlueprintReadOnly: The property is readable in Blueprints but cannot be modified.

  3. VisibleAnywhere, VisibleDefaultsOnly, VisibleInstanceOnly

    • VisibleAnywhere: The property is visible in the editor but not editable.

    • VisibleDefaultsOnly: The property is visible in the Blueprint’s default properties but not editable in instances.

    • VisibleInstanceOnly: The property is only visible when the instance of the Blueprint is placed in the level.



UFUNCTION() macro

The functions are often exposed to the engine's reflection system using the UFUNCTION() macro.


UFUNCTION() Specifiers:

1. BlueprintImplementableEvent

BlueprintImplementableEvent is used when you want to declare a function in C++ that must be implemented in Blueprints. This is useful when you want designers or other team members to provide specific behavior in Blueprints, while still declaring the function’s existence and parameters in C++. When this specifier is used, the function has no implementation in C++, only a declaration.

  • Use Case: When you want to delegate the implementation details to the Blueprint, such as handling animation events, visual effects, or game-specific logic that may change frequently.

2. BlueprintNativeEvent

BlueprintNativeEvent allows you to provide a default implementation of a function in C++ but also gives the option for it to be overridden in Blueprints. This specifier is ideal when you want to provide a base behavior while giving designers the flexibility to customize or extend the functionality in Blueprints.

  • Use Case: When you want to provide a default behavior (e.g., default movement or interaction logic) but allow the possibility for Blueprint customization.

3. BlueprintCallable

BlueprintCallable is used when you want a function written in C++ to be accessible and callable from Blueprints. This specifier is the most commonly used when exposing functions that interact with the game state, character behavior, or any other gameplay system that needs to be accessible from Blueprint scripting.

  • Use Case: When you want Blueprint designers to call a C++ function directly, like applying damage or interacting with objects.

4. BlueprintPure

BlueprintPure is used for functions that do not alter the state of the object (or the game) and are only intended to return information. These functions are displayed differently in Blueprints as they do not have an execution pin. Instead, they simply output their result, making them suitable for getters or utility functions.

  • Use Case: When you want to create a utility function that retrieves data or calculates a value without causing side effects.

Comments


bottom of page