I then detect through the CanEditChange function in the code when the struct is drawn and i get it in as the property so i do the following in the .cpp file:
if (InProperty->GetFName() == FName(TEXT("Values")))
{
const UStructProperty* StructProperty = Cast<UStructProperty>(InProperty);
if (StructProperty)
{
UScriptStruct* ScriptStruct = StructProperty->Struct;
if (ScriptStruct)
{
UProperty* ChildProp = ScriptStruct->FindPropertyByName(FName("EnumValue"));
if (ChildProp)
{
UEnumProperty* EnumProp = Cast<UEnumProperty>(ChildProp);
if (EnumProp)
{
//HOW DO I RETRIEVE DATA FROM THE ENUM PROPERTY?
}
}
}
}
All the casts succeed but I simply can’t get the actual value of enum ouf of it. I’ve tried casting it to UByteProperty (cast successful) but none of the values I retrieved from any of the “Get” functions in that were correct.
that how i do for bools, so it should work for other values types
UObject* ownerObject; // in your case 'this' you need to get the pointer to the struct
UEnumProperty* EnumProp;
eMyEnum * ptrValue = EnumProp->ContainerPtrToValuePtr<eMyEnum >(ownerObject);
if (ptrValue)
{
if ((*ptrValue) == eMyEnum::VAL_1);
{
}
}
I’ve tried using the actor itself, the StructProperty pointer, the StructScript, and every other value i could think of as the ownerObject but it always crashes on the same spot.
I can’t seem to access the struct directly to plug it in like I could in previous cases where I used the Properties in this manner.
I think I will have to find an alternative solution to this as I can’t really wrap my head around it at the moment - but I think the approach is correct.
I wanted to check the value of the enum to dynamically disable fields that shouldn’t be edited based on enum choice. I already do a similar thing (but without array involvement) in another place - just wanted to see if I could get that same customization working through in an array too.
Reality is the correct way to go about it would be through would likely be:
But I just wanted a quick temporary solution and not go into slate level customization but I guess that will likely be the way I’ll have to do it.
This is true, I had a “hacky” workaround where I actually managed to get the project to compile with where I ‘saved’ the value even though it shouldn’t be possible due to const function. And I wanted to use that value no the underlying EditChanges for the specific sub properties of the struct.
But alas I never got that far since I could never get the right value from the enum.