What's the best way to support Large World Coordinates in C++

Previously we had floats everywhere.

Now it seems like we support either float or double depending on if large world coordinates are used.

Is there a good standard way to write C++ code? I’d think it’d be convenient if there was some define in C++ like this:

#ifdef LWC_ENABLED
typedef Real double
#else
typedef Real float
#endif

I noticed unreal has templated versions of TVector now and some UE_DECLARE_LWC_TYPE macros, but it’s not obvious how they work.

Actually I did find an article and tried something like this:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Rotation")
FRotator::FReal AnimationSpeed = FRotator::FReal(5);

I get some crazy compiler errors. Looks like Unreal Header Tool is having an issue with those types. I saw most unreal UPROPERTY values still use float.

  RDBaseHierarchicalRotationController.h(121): [] Missing variable name
  Error reentered: Assertion failed: SuperClassDef->GetClassWithin() [File:C:\Code\Experimental\UnrealEngine\Engine\Source\Programs\UnrealHeaderTool\Private\HeaderParser.cpp] [Line: 8611]
  === Critical error: ===
  Error reentered: Assertion failed: SuperClassDef->GetClassWithin() [File:C:\Code\Experimental\UnrealEngine\Engine\Source\Programs\UnrealHeaderTool\Private\HeaderParser.cpp] [Line: 8611]
  
  HandleError re-entered.
  Assertion failed: SuperClassDef->GetClassWithin() [File:C:\Code\Experimental\UnrealEngine\Engine\Source\Programs\UnrealHeaderTool\Private\HeaderParser.cpp] [Line: 8611]

The article itself:

I have some shared code between 4.x and 5.x so I ended up just creating some defines for the Vectors I was using:
#if ENGINE_MAJOR_VERSION>4
#define rdVector2 UE::Math::TVector2
#define rdVector UE::Math::TVector
#else
#define rdVector2 FVector2D
#define rdVector FVector
#endif

It seems like maybe UE is in a half way state right now when it comes to supporting this, considering Epic’s own code still uses floats in many places when UPROPERTY is involved.

Unreal Header tool always typically seemed to have trouble unless you write out the actual type. It doesn’t work with #defines which is very frustrating since we can’t use a feature of C++ that is essential for something like this.

I’m guessing UHT looks at what is literally written when parsing UFUNCTION and UPROPERTY and doesn’t resolve the preprocessor macros.

If you write this, UHT may have issues.

UPROPERTY()
rdVector2 SomeVector;