The problem

I am attempting to use a TEnumAsByte in one of my class headers:

I get compilation errors:

Compilation errors.

Code sample

I have included everything relevant to the member variable I am trying to create:

Header File:

#pragma region Engine Includes

#include <Containers/EnumAsByte.h>

#pragma endregion

UCLASS( Blueprintable, ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class PLATFORMER_API UGrappleAbilityComponent : public UActorComponent

    // Begin AActor Interface //

    /** Called when play starts */
    virtual void BeginPlay() override;

    // End AActor Interface //

    /** Determines what type of debug draw is used for the continuous grapple scanning */
    UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Grapple Scan", meta = (AdvancedDisplay, DisplayName = "Grapple Cont Scan Debug Draw Type"))
        TEnumAsByte<EDrawDebugTrace::Type> m_GrappleScanDebugDraw;

Source File:

    PrimaryComponentTick.bCanEverTick = true;

    // Give an initial value to the debug draw mode for the continuous grapple scanning.
    m_GrappleScanDebugDraw = EDrawDebugTrace::None;


void UGrappleAbilityComponent::GrappleScanContinuous(FHitResult & OutHit)
    // Only scan if the player is not attached and their airbrake is not active
    if (!m_GrappleHook->IsAttached() && !m_OwnerCharacter->IsAirbrakeActive()) {

        // Increment the trace lerp value.  -   Then wrap the Trace lerp value back around to 0.
        m_GrappleScanTraceLerp += 0.1f;         if (m_GrappleScanTraceLerp > 1.f) { m_GrappleScanTraceLerp = 0.f; }

        // Calculate the proposed end point of the grapple.
        FVector EndPoint = m_StartPoint + m_StartPointDirection * m_GrappleCastDistance;
        float zOffset = FMath::Lerp(m_GrappleContScanLowHeight, m_GrappleContScanHighHeight, m_GrappleScanTraceLerp);
        EndPoint.Z += zOffset;

        // Perform the box traces.
            m_StartPoint, EndPoint, m_GrappleContScanHalfSize, FRotator::ZeroRotator, 
            false, {}, m_GrappleScanDebugDraw.GetValue(), OutHit, true);

Additional Info

The compilation errors relating to the BoxTraceSingle call are irrelevant as they only occur due to the compilation errors with the TEnumAsByte. Aside from the .GetValue() call. Removing this still causes similar compilation errors however.

I can confirm this as, by looking at Epic's engine code, they use TEnumAsByte in exactly the way I have done here, aside from the .GetValue() call.

What the hell is going on here?


Error C2653, the first one, says that EDrawDebugTrace isn't a class or namespace name, which is another way of saying (in this context) that the compiler has not yet seen a definition for EDrawDebugTrace. That's the root of your problem.

Error C2923 is telling you that you cannot use EDrawDebugTrace::Type as a parameter for the template TEnumAsByte<>. The reason you cannot use Type is because the compiler doesn't know what it is, since it's nested inside EDrawDebugTrace which the compiler also doesn't know about (because of the first error).

At this point in your code, the only #include you have is for TEnumAsByte<> itself. This header does not define EDrawDebugTrace (instead, it comes from the KismetSystemLibrary.h header).

To fix this, you should include KismetSystemLibrary.h (or some other header that includes it indirectly) in your code before you try to use EDrawDebugTrace.

  • \$\begingroup\$ Thanks for the detailed answer! It's interesting that it's so hard to diagnose that as an error when without including the header, the enum values within the namespace are visible. \$\endgroup\$ – Natalo77 Nov 18 '19 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.