How to override C++ function in Blueprint?

There is some function, which I gonna to override in Blueprint

.h file:

UFUNCTION(BlueprintCallable, Category = RemoteServer)
virtual void ServerMsg(const FString& msg);

.cpp file:

void UCrazyRacingGameInstance::ServerMsg(const FString& msg)
{
 	PRINT("Server message: %s", *msg);
}

This function will be called by CallFunctionByNameWithArguments method and using BlueprintNativeEvent is improperly.

If I try to define ServerMsg function in blueprint, I got the message:

Error: The function name in node Server Msg is already used
Error: Cannot override '::ServerMsg' at Server Msg which declarated in a parent with a different signature!

How to override this function? Help me please :slight_smile:

alt text

I’m afraid that you can’t declare UFUNCTIONs as virtual. At least that’s what I can tell by experience.

But compiled successfully. virtual or not virtual it makes no difference.

You can declare UFUNCTION() functions as virtual. However you can not override them inside blueprints. Only inside other C++ classes. You probably already seen that you can not see the function you declared virtual, inside blueprint editors overridable functions list.

If you want to override a function inside blueprints, you will need to use BlueprintNativeEvent or BlueprintImplementableEvent as UFUNCTION() specifiers.

2 Likes

But method CallFunctionByNameWithArguments is not applicable to Events.
Are there analogs of this method? Or this method may be used too?

Just I don’t want to increase function count in C++ code for one action.

I am not familiar with that function and it seems DOC has very little information.

Instead of function can you tell what you are trying to do? Maybe i can suggest some other approach.

I use my server for remote function calling CLIENT <–> SERVER
At case CLIENT → SERVER call I just use defined method name in C++ and place the string with the method and parameters to CallFunctionByNameWithArguments for implicit call.
But in future I think realisation can be moved also in blueprints for more extensibility.

As far as i understand, you are trying to call a function ?server has access to? from client computer. I am not experienced with networking so i cannot be of much help.

Maybe by using replication you can achieve the same effect or you can post another question regarding possible different approaches to this.

This is not UE4 server. This is remote manager for some controls.

Problem soloved. Events also can be called too by CallFunctionByNameWithArguments. Thank you for attention :slight_smile:

FindFunction and ProcessEvent is nice things too:)

does not work
does the function need to be virtual ?

Not really, just having UFUNCTION(BlueprintImplementableEvent) would work.

Try sharing what error are you getting.