# UProperty Conversions?

**URL:** <https://forums.unrealengine.com/t/uproperty-conversions/250631>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [September 14, 2021, 4:12am UTC](https://forums.unrealengine.com/t/uproperty-conversions/250631 "2021-09-14T04:12:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![areddan](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@areddan](https://forums.unrealengine.com/u/areddan)\
**Post date:** [September 14, 2021, 4:12am UTC](https://forums.unrealengine.com/t/uproperty-conversions/250631/1 "2021-09-14T04:12:08Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![MagForceSeven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/magforceseven/32/906563_2.png) [@MagForceSeven](https://forums.unrealengine.com/u/MagForceSeven)\
**Post date:** [September 14, 2021, 3:44pm UTC](https://forums.unrealengine.com/t/uproperty-conversions/250631/2 "2021-09-14T15:44:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![areddan](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@areddan](https://forums.unrealengine.com/u/areddan)\
**Post date:** [September 15, 2021, 5:01am UTC](https://forums.unrealengine.com/t/uproperty-conversions/250631/3 "2021-09-15T05:01:06Z")

</div>

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 🤔

---

<div class="post-metadata">

**Author:** ![MagForceSeven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/magforceseven/32/906563_2.png) [@MagForceSeven](https://forums.unrealengine.com/u/MagForceSeven)\
**Post date:** [September 15, 2021, 9:05pm UTC](https://forums.unrealengine.com/t/uproperty-conversions/250631/4 "2021-09-15T21:05:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![areddan](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@areddan](https://forums.unrealengine.com/u/areddan)\
**Post date:** [September 18, 2021, 4:38pm UTC](https://forums.unrealengine.com/t/uproperty-conversions/250631/5 "2021-09-18T16:38:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![areddan](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@areddan](https://forums.unrealengine.com/u/areddan)\
**Post date:** [September 18, 2021, 4:39pm UTC](https://forums.unrealengine.com/t/uproperty-conversions/250631/6 "2021-09-18T16:39:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Zeblote](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zeblote](https://forums.unrealengine.com/u/Zeblote)\
**Post date:** [September 19, 2021, 2:21am UTC](https://forums.unrealengine.com/t/uproperty-conversions/250631/7 "2021-09-19T02:21:01Z")

</div>

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…
