GET_MEMBER_NAME_CHECKED won’t work in Editor for Struct members,
only works for regular properties. i.e:
#if WITH_EDITOR
void UMyClass::PostEditChangeProperty(struct FPropertyChangedEvent& PECP) {
FName PropertyName = (PECP.Property != nullptr) ? PECP.Property->GetFName() : NAME_None;
// This wont work, it's a Struct member.
if ((PropertyName == GET_MEMBER_NAME_CHECKED(UMyClass, Identity.Random))) {
Identity.Name = FGenerateHumanName();
}
// This works just fine, it's a regular int32 property.
if ((PropertyName == GET_MEMBER_NAME_CHECKED(UMyClass, Random))) {
Identity.Name = FGenerateHumanName();
}
Super::PostEditChangeProperty(PECP);
}
#endif
Hi BrUnO,
I did some checking on what you described, and this actually appears to be working as intended. GET_MEMBER_NAME_CHECKED
only works with members of the class, but not with members of members. In your example, it should be aware of the Identity
class member, which is an instance of your struct. However, it does not look inside the struct to see what members the struct contains.
This is important for a couple reasons. First, this avoids the potential for very large numbers of variables needing to be checked. If you have a class that contains three or four members that are structs, and each of those structs contains several members that are also structs, and each of those structs contains several members that are also structs… You can see how that could very quickly become a significant challenge.
Secondly, it helps to avoid possible infinite regressions. For example, if your class contains a member that is a struct, and that struct contains a member that is a pointer to a child of your original class, you could get stuck infinitely regressing through that circular reference.
Have you seen any instances where GET_MEMBER_NAME_CHECKED
does seem to look at members of members? If so, we may need to take a closer look at those instances.
In terms of being able to do what you need to do, there are a couple ideas that may work for you. The first would be to watch for any changes to the Identity
class member, then run your own checks that need to be performed before updating Identity.Name
. The second would be to make Identity.Name
be part of the class and mirror it to the struct (or remove it from the struct entirely).
1 Like
I ended up using the Random value outside the struct, it’s good enough.
Thanks for the explanation btw.