So confused on Macros


So i have absolutely no idea where some of these APIs (?) are coming from and how on earth we would know to use them etc. They feel like they are just coming out of left field.

Im talking about the part on :

float OpenAngle = 90.0f;

ATriggerVolume* PressurePlate;

I am 2 semesters into a CS degree and we’ve talked about calling methods, writing our own constructors etc, but this whole concept of whatever UPROPERTY() written the way it is with no ; , no space after, and putting the next line directly below it feels very foreign and an odd coding format.
Even this page tells me just about nothing and feels way over my head


Not sure what you mean by CS degree as I refer to CS as CSharp/C# but Unreal is using C++ (didn’t hear it’s also possible to program in C#,not sure though).
Actually there’s some macros where it doesn’t matter if you add a semicolon like e.g. UE_LOG() because these macros don’t rely on any other code around it while UPROPERTY() / UFUNCTION() rely on its following Variable / Function Declaration. That’s why there cannot be anything inbetween the macro call and the variable/function declaration that follows except spaces/tabs. Not sure again, but as I understand, these specific “macros” are not a C++ thing but an Unreal thing, even though a form of macros (#define) does exist in C++!



CS also means Computer Science in this context I would think, anyway… about MACROs

A macro tells the compiler to replace the macro name with text defined somewhere else. You can right click on the macro and “goto definition” to see what it is doing, usually.

In this case it is more complex in that its not a compiler macro but one that is used by Unreal’s Unreal Header Tool. or UHT which runs before the code is sent to the compiler. So the UHT looks at your source code, modifies that code where it sees a macro that it knows, and then compiles the result.

Since UPROPERTY() is a macro that is qualifying the following type declaration there can be no semicolon trailing it. It is going to add code to the beginning of the declaration that will integrate the object into the game framework so a semicolon would break the connection between the new text and your type.

I would expect there is a way to see the resulting post macro pre-compile files somehow but I am new to VS and windows dev so I cannot say where you would find them. They don’t appear to be anywhere in the project hierarchy so maybe they only exist temporarily? It would be interesting to see what the macros expand to.


Yes , Computer Science is what I meant.

Thanks for this explanation, it helps a little, I did follow UPROPERTY to its definition but its oddly complex and Im not too familiar with C++ only been learning Java.
Not sure what the " (…)" are after #define UPROPERTY(…)


The “(…)” provides variable arguments to the macro function. It does get a little abstract but here is the language specification for it: Replacing text macros

If you check out the UE docs about the macro it shows that you can add a lot of stuff in there, not just the one flag that we are using so far. Would need to see the source for the Header Tool to see how the macro is actually defined, but that may only exist in binary. Will post here if I find anything more about it.