Download

Trying to create a macro for RPCs leads to unresolved symbols

It’s annoying to have to write 4 functions for server packets, especially when a variable changes. It also clutters up my header file. I was trying to make a preprocessor macro.


// Send a Chat to the Server
UFUNCTION(Reliable, Server, WithValidation)
void ServerSendChat(EPlayerChatChannel ChatChannel, const FString& Message, const FString& Override);
void ServerSendChat_Implementation(EPlayerChatChannel ChatChannel, const FString& Message, const FString& Override);
bool ServerSendChat_Validate(EPlayerChatChannel ChatChannel, const FString& Message, const FString& Override);
void SendChat(EPlayerChatChannel ChatChannel, const FString& Message, const FString& Override);


#define UNREAL_SERVER_FUNCTION(FunctionName, ...)			\
void FunctionName##( __VA_ARGS__);							\
UFUNCTION(Reliable, Server, WithValidation)				\
void Server##FunctionName##(__VA_ARGS__);						\
void Server##FunctionName##_Implementation(__VA_ARGS__);		\
bool Server##FunctionName##_Validate(__VA_ARGS__);


UNREAL_SERVER_FUNCTION(SendChat, EPlayerChatChannel ChatChannel, const FString& Message, const FString& Override)

The problem is Unresolved External Symbols on the Server##FunctionName##(), meaning Unreal isn’t generating that function. I am guessing this macro doesn’t inline everything needed for Unreal’s reflection system. Any suggestions?

I’m willing to bet that it’s something to do with UHT and the generated headers. I’m assuming you’ve gone and created the _Implementation and _Validate functions in the CPP as well? If you don’t it will throw that link error.

Oh and, if you’re using GENERATED_UCLASS_BODY instead of GENERATED_BODY for whatever reason, it automatically creates those extra functions in the header.