UProperty Conversions?

Hi all, I’m wondering if its possible to serialize a value differently to how we present it for configuration. A simple example would be configure in degrees but serialize in radians. This way I could expose a property however the designer wants, but avoid unnecessary runtime conversion.

Is it possible?

Any ideas otherwise? Maybe with IPropertyTypeCustomization or PostEditChangeProperty?

Either one of those should work, PostEditChangeProperty is probably easier. Either way you’d need to have two members: one that is editable, in degrees, and is unused by the game. The other that isn’t editable, in radians, and is used by the game. You won’t be able to use the same member for both purposes.

However, “unnecesary runtime conversion” sounds like a speculative/premature optimization that may not be worth the effort for the payoff.

Thanks! Yeah it’s not necessarily about the optimization (though that’s nice - why do at runtime what you can do during packing/serialization), but also keeping runtime code clear and concise. Would be nice to not have to convert a value every frame or even just have to deal with that conversion on initialization with additional members to store the converted value.

It’s a very minor thing, but typically how I’ve worked with other engines in the past (I’m pretty new to UE).

Custom UProperty attributes or MetaData would be nice to have for cases like this :thinking:

Yeah, I worked in a custom engine that allowed for that sort of thing fairly easily. However Unreal does run into that particular limitation due to the fact that single structure is used for both Editor and Game. At best you could #ifdef the Degrees member so that it was only available for Editor builds. It may not matter for a single float, but it is marginally closer to what you’re trying to do.

PostEditChangeProperty is still probably the way to go, updating the game value on each change. A hook on cooking (ie packing) would mean the game value isn’t being updated for use in the Editor (Play In Editor/PIE). And a hook on serialization would similarly not necessarily update within a single Editor session, which again would affect your ability to test changes using PIE.

One nice thing about Unity + Odin Serializer is we could expose a property that did the conversions on the radian serialized data. This way you still load and save in radians, but its presented to the designer in degrees. Anyways, I can give it a go with the PostEditChangeProperty hook but if that is too convoluted its not gonna be worth it as you mentioned.

I guess in Unity you could also have a custom property attribute to handle that too!

This is what a details customization is intended for - display a property differently in the editor than what the automatic widget would do. Unfortunately it is very clunky to implement these…