IWYU, Raw pointer detection and UE_INLINE_GENERATED_CPP_BY_NAME static analysis

Hello!

I assume internally you have a few tools to prevent and audit some of your best practices, such as IWYU, using TObjectPtr instead of UPROPERTY, and UE_INLINE_GENERATED_CPP_BY_NAME.

I was hoping you might be able to shed light on how you stay on top of this and track it. Ideally, these are publicly available so we can simply add a parameter to the submit tool’s static analysis to prevent new instances, and use something to generate a report of our current violations.

If there are any other best practices you’d recommend auditing and monitoring early, we’d be happy to hear about those as well.

Additionally, for the TObjectPtr conversion, would we need to convert third-party plugins to be compliant in order to enable incremental GC/cooking, or would we simply not see the benefit for the portions we don’t convert?

Hello!

Regarding the usage of TObjectPtr:

  • The UnrealHeaderTool can validate the usage of TObjectPtr
  • This can be configured in Engine\Programs\UnrealHeaderTool\Config\DefaultEngine.ini
    • Set NonEngineNativePointerMemberBehavior to ‘Disallow’
  • We are enforcing the usage of TObjectPtr for all Engine code (engine and plugins) currently although this not directly visible to licensees.

Regarding UPROPERTY vs TObjectPtr, those are orthogonal concepts and can be used at the same time. UPROPERTY is still required to have the reflection code generated on the class members and this is also needed for the GC to know about those references. TObjectPtr is only used at the editor level for different purposes.

The Incremental cook is one of the user of TObjectPtr BUT this is not mandatory. It is highly recommended though. Without it, there might be bugs related to asset not being re-cooked when needed with non-engine types.

Finally, UE_INLINE_GENERATED_CPP_BY_NAME can be tracked by UBT by using the CppCompileWarningSettings.NonInlinedGenCppWarningLevel attribute in ModuleRules (build.cs). The default is to have that off by default. You can add the following in your ModuleRules:

CppCompileWarningSettings.NonInlinedGenCppWarningLevel = WarningLevel.Warning;

Please note that WarningLevel.Error will result in warnings at this point. I’ll work with the team to get this fixed.

Martin

I need to backtrack a bit on my comment on the TObjectPtr. A colleague notified me that it is not being used for some runtime usage such as the incremental GC. This doens’t supersede the need to declare the members as UPROPERTY. And I also need to warn you that the Incremental GC has only been tested\validated on single threaded servers. The feature is not safe in the editor or a game client.

Thanks! We aren’t looking to use the incremental GC right now, but just want to avoid having to do a larger clean up later. I’ll look to integrate those flags so we can stay on top of them.