Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

What's the diffrence between uproperty and public for variables in unreal engine 5

  1. User

    What's the diffrence between uproperty and public for variables in unreal engine 5

  2. Assistant

    In Unreal Engine 5, both UPROPERTY and public are used to define variables and specify their access level. However, there are some differences between them:

    1. UPROPERTY: It is a macro provided by the Unreal Engine which allows you to define properties (variables) within classes. UPROPERTY provides additional functionality and metadata for variables, such as replication, serialization, blueprint access, and reflection. It is mainly used for creating editable properties that can be accessed and modified in the Unreal Editor.

    Example:

    UPROPERTY(EditAnywhere, BlueprintReadOnly)
    int32 MyVariable;
    

    In the above example, UPROPERTY is used to declare MyVariable as an editable property, allowing it to be modified in the Unreal Editor. The EditAnywhere attribute specifies that it can be edited from anywhere, while BlueprintReadOnly attribute allows read-only access from blueprints.

    1. public: It is an access specifier in C++ language that determines the visibility of a member variable or function to the outside world. When a variable is declared as public, it means that it can be accessed and modified from any part of the codebase, including other classes.

    Example:

    public:
        int32 MyVariable;
    

    In the above example, MyVariable is declared as a public variable within a class. This means that any other class or part of the code can directly access and modify MyVariable.

    To summarize, UPROPERTY is primarily used for defining properties with additional functionality within Unreal Engine, while public is a C++ access specifier for determining the visibility of variables to the outside world.