I’m investigating whether Unreal’s reflection metadata can safely be enabled at runtime in non-editor builds.
UE5’s reflection system tracks metadata for USTRUCTs/UCLASSes/UFUNCTIONs and their properties.
However, the metadata is only present in the editor build - it can’t be accessed in the cooked builds as all metadata functionality is ifdefed away due to the WITH_METADATA preprocessor macro which is enabled only in the editor.
I tried defining the WITH_METADATA macro permanently for all configurations and it seems that this is not something that is done usually as it caused a few compilation errors (MSVC 19.44.35215). However, after fixing those the engine & cooked game both seem to run well.
Therefore, I would like to ask whether there are some potential downsides to enabling WITH_METADATA in non-editor builds. Would you recommend against this approach? Why is the metadata not present in the non-editor builds by default?
Hi,
Normally, we you would want to turn everything that is not required off in your cooked builds. If you turn the meta-data on, the side effects that I can think of are:
- Increased code bloat - This definitely add extra code. The binary itself will be bigger and the extra code will use more memory. More code can also make it less cache-friendly, though this needs to be measured to be sure.
- Increased Memory usage - You add meta-data, so you pay an extra memory cost at runtime somewhere.
When you run on a console or a low end mobile device with a tight memory budget, you are happy to save as much as you can. I’m not sure performance wise what would be the impact, but there is probably one too. Internally, we don’t test that at all, so you might suffer from unknown side effects. What’s your use case?
Regards,
Patrick
We were considering using the metadata as a source of additional information for XML deserialization, but have scrapped the idea for now. Thanks for the answer and explanations.