What is the difference between a variable declared using UPROPERTY() macro and a variable declared without UPROPERTY() MACRO?

UPROPERTY() macro by it self is just dummy, this macro is marker for different tool called UnrealHeaderTool. UHT generates code before compilation that registers the variables (UPROPERTY), functions (UFUNCTION) class (UCLASS), structs (USTRUCT) etc. with extra meta data (that you add to that macro) to the UE4 reflection system.

C++ code is transformed in compilation process to CPU machine code and all varables object classes etc. don’t physicly exist there they striped from there body, all variables are converted to memory addresses, classes and structs are just memoery stractures which are accessed as normal varbales etc. because of that code it self is not aware of it’s own structure, don’t see it self, thats why it need reflection system in order to identify it’s own elements, byt for example by assigning names to specific memory addresses which later can be discovered and referenced in user interface (like property editor in UE4 editor) and UE4 has such system and those macros and UHT is part of it which tracks those varables before compilation and generates code that registers those, allowing UE4 to create kind of like map of it self, creating all those UClass* object that you interact in the code

If specific macro is missing that variable, class etc. won’t be visible to the engine and any memory management system that it has, it’s became pure C++ varable and needs to be managed manually like in pure C++, also some features require elements that are visible in UE4 reflection system in order to be used in them, for example functions that are used in UE4 timers need to be visible in reflection system and have that UFUNCTION(). And yes this naturally means that those variables are not cleaned by memory management, you need to manage them manually.

Some types are not supported by reflection system (like pointers to non-UObjects types), so you are forced to remove UPROPERTY() and manage them manually if you really want to use them. Also UCLASS() works only with UObjects and all UObjects need UCLASS() or else they will be broken and won’t work because engine needs to see them in order for them to work properly.

1 Like