TEnumAsByte Causes Compile Error in Replicated Functions

Dear Friends at Epic,

I am getting a misleading compile error when I try to use TEnumAsByte within the function parameters of a server function!

#TEnumAsByte for This Enum

UENUM(BlueprintType)
namespace EJoyMovement
{
	//256 entries max
	enum Type
	{
		Hover				UMETA(DisplayName="Hover"),
		Rolling				UMETA(DisplayName="Rolling"),
		Ground				UMETA(DisplayName="Ground"),
		
		//~~~
		
		//256th entry
		EJoyMovement_Max		UMETA(Hidden),
	};
}

#The Compiler

The compiler simply says it cant find the function, which is very misleading.

Really the issue is is that you can’t use TEnumAsByte with replicated functions, at the moment.

Though I can’t see why this is an existing limitation?

#This Works

UFUNCTION(reliable, server, WithValidation)
void SERVER_SetJoyMove(EJoyMovement::Type NewJoyMode);

cpp

bool AJoyMovement::SERVER_SetJoyMove_Validate(EJoyMovement::Type NewJoyMode)
{
	return true;
}

void AJoyMovement::SERVER_SetJoyMove_Implementation(EJoyMovement::Type NewJoyMode)
{

#This Doesnt

UFUNCTION(reliable, server, WithValidation)
void SERVER_SetJoyMove(TEnumAsByte<EJoyMovement::Type> NewJoyMode);

cpp

bool AJoyMovement::SERVER_SetJoyMove_Validate(TEnumAsByte<EJoyMovement::Type> NewJoyMode)
{
	return true;
}

void AJoyMovement::SERVER_SetJoyMove_Implementation(TEnumAsByte<EJoyMovement::Type> NewJoyMode)
{

#Compile Error

1>C:\Users\\Documents\Unreal Projects\JoyShapes\Intermediate\Build\Win64\Inc\JoyShapes\JoyShapes.generated.cpp(1104): error C2511: 'void AJoyMovement::SERVER_SetJoyMove(EJoyMovement::Type)' : overloaded member function not found in 'AJoyMovement'
1>          C:\Users\\Documents\Unreal Projects\JoyShapes\Source\JoyShapes\Private\Characters\JoyMovement.h(14) : see declaration of 'AJoyMovement'
1>C:\Users\\Documents\Unreal Projects\JoyShapes\Intermediate\Build\Win64\Inc\JoyShapes\JoyShapes.generated.cpp(1107): error C2352: 'UObject::FindFunctionChecked' : illegal call of non-static member function
1>          e:\victoryue4\unrealengine-4.2\engine\source\runtime\coreuobject\public\uobject\UObject.h(568) : see declaration of 'UObject::FindFunctionChecked'
1>C:\Users\\Documents\Unreal Projects\JoyShapes\Source\JoyShapes\Private\Characters\JoyMovement.cpp(28): error C2511: 'bool AJoyMovement::SERVER_SetJoyMove_Validate(TEnumAsByte<EJoyMovement::Type>)' : overloaded member function not found in 'AJoyMovement'
1>          c:\users\\documents\unreal projects\joyshapes\source\joyshapes\private\characters\JoyMovement.h(14) : see declaration of 'AJoyMovement'
1>C:\Users\\Documents\Unreal Projects\JoyShapes\Source\JoyShapes\Private\Characters\JoyMovement.cpp(33): error C2511: 'void AJoyMovement::SERVER_SetJoyMove_Implementation(TEnumAsByte<EJoyMovement::Type>)' : overloaded member function not found in 'AJoyMovement'
1>          c:\users\\documents\unreal projects\joyshapes\source\joyshapes\private\characters\JoyMovement.h(14) : see declaration of 'AJoyMovement'

#:heart:

Hi ! Thank you for being so awesome!

Can you show me what your header looks like where you declare the function as replicated?

Hee hee, you’re welcome!

:slight_smile:

I’ve added the respective header code to my original post!

Have fun today !

#:heart:

Ok yeah that clarifies things, I know that the UHT generates the method prototypes for the actual SERVER network thunks, and it probably unwraps the EnumAsByte<> part of this, so my guess is that the intention is that the implementations use the actual Enum, where-as the prototype UFUNCTION() needs to use EnumAsByte<> for the metadata part.

That’s a great analysis!

I would like Epic to address this because it seems like something that should be easy to handle so it doesnt throw a compile error :slight_smile:

Having cases where you should and shouldn’t use TEnumAsByte gets rather confusing for those new to the Engine.

Not only to those new to the engine, I also got stuck in this problem! Thanks for sharing the solution!

got the same issue which was fixed with the same fix while calling a BlueprintImplementableEvent from c++

Hi everyone,

Sorry for the delay on getting a response for this issue. I just wanted to let you know that a report for this issue has been sent to our development team (UE-4445) and they will investigate this issue further.

Thanks !

:slight_smile:

Was this ever fixed?

This isn’t a bug per-se, just don’t use TEnumAsByte in functions, TEnumAsByte is only needed for UPROPERTY’s

Hi Zoc,

I checked the status of the ticket I had entered for this, and it is currently backlogged. Just to make sure you are aware, if you are using strongly-typed enums based on uint8, it may not be necessary to use TEnumAsByte<>, even with UPROPERTYs.