How do i code server rpc in 4.7 ?

Hey guys,

You’ve got a working code in post #29 of this thread :wink:

Cheers

Cedric

I’m also having the “member function already defined or declared” problem. I declared it on the header like this:



UFUNCTION(Server, Reliable, WithValidation, BlueprintCallable, Category = "Test")
void ServerTest(int32 Value);

virtual bool ServerTest_Validation(int32 Value);
virtual void ServerTest_Implementation(int32 Value);


Error 1 error C2535: ‘void ATest::ServerTest_Implementation(int32)’ : member function already defined or declared

This is on the 4.7 release version that was made available today.

Hi xlar8or,

You have “Validation” instead of “Validate”, that might be a possible cause for your problem.

Cheers

Cedric

That’s why you should always copy from the cpp and not write it yourself :stuck_out_tongue: The error was misleading indeed. Thank you :slight_smile:

Apparently my error was that I had virtual void function_Validate at some point instead of virtual bool, which led to a barrage of error messages.

There is also a nasty little pitfall where commenting out the _Validate and and _Implementation declarations will lead to the same errors (not warnings, errors). I guess the precompiler gets confused by this somehow. Comments breaking code is pretty unexpected to say the least.

I’m getting these ‘already declared’ errors as well:


error C2535: 'void ABall::OnKick_Implementation(void)' : member function already defined or declared

I don’t have any validation method, as my RPC is marked Unreliable. I have no idea how to fix this, because if I remove the declaration I get deprecation warnings.

It seems if you don’t also define the _Validate method, the UHT assumes you’ve not defined either of them, so defines them both. Because checking for each one individually is a real pain?!

This would have made a lot more sense if it had complained about the lacking _Validate method as well… but it doesn’t.

Unreliable means it’s not guaranteed to be executed, not that it’s not validated. Doesn’t it? The _Validate method is added with the WithValidation specifier.

I think you are correct, but even if you are, I also have no WithValidation, yet I’m getting the error.

I think all server methods need to be validated now. Just make it a stub that always returns true if there’s nothing to validate.

Code Sample

this



UFUNCTION(Reliable,Server,WithValidation)
void SERVER_UpdateArmorMorph(FName Name, float Value);


becomes this



UFUNCTION(Reliable,Server,WithValidation)
void SERVER_UpdateArmorMorph(FName Name, float Value);
**bool** SERVER_UpdateArmorMorph**_Validate**(FName Name, float Value);
void SERVER_UpdateArmorMorph**_Implementation**(FName Name, float Value);


I think the confusing part is that _Validate returns a bool not void, other than that just be sure to include both function definitions as well as WithValidation in your function definition.

Enjoy!

If all RPC calls now must have WithValidation, they might as well just remove the tag altogether and make add it by default. I can’t test if my code works if I add validation atm.

I believe only client to server requires validation, so I guess the other way around it’s still optional. I can’t remember where I read this, it must have been in one of the replication guides. Would be good to get confirmation by an expert.

Okay, my question is, why do they have to do this? Is there any good reason to change it at all?

Having to break every network codes into three functions seems very ridiculous when you’re trying to make Unreal easy for most people.

We’re midway into completing our project and we have over 500+ network functions. So is this for permanently real, or will they decide to randomly change it back again in later version?

ps. Just make a request post for Epic to bring the automation back.

Please support this if any programmer out there like the old RPC automation like us.

I have a bit of a background in the programming side of 4.5, and it seems like alot of the functionality that was in 4.5 is now depricated. Is there a location to maybe a list or reference to all these deprecated functions/functionalities???

Hi PsiGames, everything should be listed in the release notes.

At first I was puzzled by why this change to RPCs was necessary but I quite like it know after realizing that this solves an issue with IntelliSense (Visual Studio auto-complete): before while implementing the implementation and validate functions Visual Studio would not recognize those functions as part of the class until it had been compiled one time, because only then the auto-generated headers were available. Every time a function’s name or format changed, you would again need to recompile to update the auto-generated headers. Now since you declare the functions yourself you don’t need to recompile before IntelliSense recognizes the functions.

I suspect the main reason for this change was to remove the awkwardness of having to run unreal header tool (as part of compiling) once to have auto-completion work.

In general changes like this are to remove the awkwardness of some of the legacy UObject stuff. Some people were confused they need to define a function they haven’t declared. There’s more stuff like this. I’m hoping that one day we can bring UObjects really close to how a normal C++ would look and work with all the extra features that they provide.

In 4.8 we’re also adding the ability to specify those _Validate and _Implementation function names so that you’re not tied to some predefined naming conventions.