Safely find a reflected property name?

Hi all…

I need to access a UPROPERTY of a UCLASS through reflection in C++. It shouldn’t present any challenge in itself, something along the lines of:

MyObject->GetClass()->FindPropertyByName(TEXT("MyPropertyName"));

However I’m absolutely certain that there’s a preprocessor macro that provides safe way to reference a property name in C++, that will throw a compile time error in the event that the name changes. Something like this:

FName PropertyName = MAGIC_PROPERTY_MACRO(MyClass::StaticClass(), TEXT("PropertyName"));
Settings->GetClass()->FindPropertyByName(PropertyName);

Can anyone remember what this macro’s called? It’s a bit tricky to find-in-all-files within the source code as I just can’t remember any part of its name! (Tried searching for safe property, things like that - also tried googling for half an hour). Gone through UClass.h to no avail.

1 Like

Ah found it… GET_MEMBER_NAME_STRING_CHECKED.

UProperty* Property = UStaticMesh::StaticClass()->FindPropertyByName(GET_MEMBER_NAME_STRING_CHECKED(UStaticMesh, SectionInfoMap));

For anyone else reading this in the future, there’s also GET_FUNCTION_NAME_CHECKED.

5 Likes