Copy enums from struct to struct

Vesper
Mon, 23 Aug 2021 03:46:42 +0000
Editor Scripting

Hey all,

I’ve got a pair of structs which both inherit from the same parent, and both have the same enum UProperties inherited from the parent, of which there are at least 20+ enum properties, and at some points, I want to copy the enums from one struct to the other without having to manually list out each enum property = other enum property for the sake of extensibility.

So I’ve got a TFieldIterator loop which successfully iterates through and retrieves the UEnumProperty’s, but when trying to use the StructA->SetEnum(StructB->GetEnum()), it throws an error (though doesn’t crash the engine).

The code so far…

for (TFieldIterator<UProperty> PropIt(OriginalStruct.StaticStruct()); PropIt; ++PropIt)
	{
		UProperty* Property = *PropIt;
		UEnumProperty* EnumProperty = FindFProperty<UEnumProperty>(AddedStruct->StaticStruct(), Property->GetFName());

		if (EnumProperty)
		{
			UEnumProperty* OriginalEnumProperty = CastFieldChecked<UEnumProperty>(Property);
			if (OriginalEnumProperty)
				EnumProperty->SetEnum(OriginalEnumProperty->GetEnum());
		}
	}

Any ideas?

1 post - 1 participant