Announcement

Collapse
No announcement yet.

How do i code server rpc in 4.7 ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How do i code server rpc in 4.7 ?

    Hey guys,

    How am i supposed to deal with server rpc in 4.7 ?

    I have a ton (one for each rpc) of warnings like that one:

    Code:
     warning C4996: Function YagActor::ServerSetBodyTexturePath needs native implementation by virtual void ServerSetBodyTexturePath_Implementation(const FString& NewBodyTexturePath) due to its properties.
    Maybe it is obvious and self explanatory but i am not a big guy in c++ and couldn't find a way to get rid of those.

    Here is my code, it has been ok until 4.7:

    Code:
    UFUNCTION(Server, WithValidation, Reliable)
    	 void ServerSetBodyTexturePath(const FString& NewBodyTexturePath);
     
     --------------------------------------------------------------------------------------------------
     
     bool AYagActor::ServerSetBodyTexturePath_Validate(const FString& NewBodyTexturePath)
     {
    	 return true;
     }
     
     void AYagActor::ServerSetBodyTexturePath_Implementation(const FString& NewBodyTexturePath)
     {
    	 bla bla
     }
    Could anyone give me an example of how server rpc should be declared in 4.7 ?

    Thanks !

    Cedric

    #2
    https://docs.unrealengine.com/latest...ver/index.html

    The function is only executed on the server. Provide a body named [FunctionName]_Implementation instead of [FunctionName]; the autogenerated code will include a thunk that calls the implementation method when necessary.

    Comment


      #3
      Hi,

      Look at my code, this is what i am already doing.

      It worked well in 4.5 and 4.6 and now generates a warning.

      If i declare it with _Implementation i get a compilation error, which, interestingly enough, comes back to warning if i add the word virtual.

      This:

      Code:
      UFUNCTION(Server, WithValidation, Reliable)
      	virtual void ServerSetupYagFdPGeneral_Implementation();
      produces this:

      Code:
      1>C:\Users\cedric\Documents\Unreal Projects\yag 4.7\Source\yag\game/YagGameState.h(49)( : warning C4996: Function YagGameState::ServerSetupYagFdPGeneral_Implementation needs native implementation by virtual void ServerSetupYagFdPGeneral_Implementation_Implementation() due to its properties. Currently ServerSetupYagFdPGeneral_Implementation_Implementation declaration is autogenerated by UHT. Since next release you'll have to provide declaration on your own. Please update your code before upgrading to the next release, otherwise your project will no longer compile.
      Notice the function_Implementation_Implementation: the macro now thinks my function name is now function_Implementation and wraps it with a new _Implementation, but still recognizes the same cpp code with no error.

      Cheers

      Cedric

      Comment


        #4
        Have not tested 4.7 yet but here is a snip for you from 4.x - 4.6

        Code:
        	UFUNCTION(Server, Reliable, WithValidation)
        		void SERVER_SetPlayerHealth(float NewHealth);
        Code:
        void AMyPlayerClass::SERVER_SetPlayerHealth_Implementation(float NewHealth)
        {
        	//..
        }
        
        bool AMyPlayerClass::SERVER_SetPlayerHealth_Validate(float NewHealth)
        {
        	return true;
        }
        Last edited by WCode; 01-12-2015, 03:27 AM.

        Comment


          #5
          Hi,

          Thanks, but if i am not mistaken, that's exactly what i am currently doing (see the code in my initial post). Worked well until 4.6, but generates warnings in 4.7.

          Cheers

          Cedric

          Comment


            #6
            Did you tried to switch Reliable and WithValidation attributes ? UBT can be sometimes picky about order things in UFUNCTION() or UPROPERTY().
            https://github.com/iniside/ActionRPGGame - Action RPG Starter kit. Work in Progress. You can use it in whatever way you wish.

            Comment


              #7
              Good idea, but unfortunately the warning is still there after the switch.

              Comment


                #8
                Ha!
                I have idea.
                Change passing by reference, to passing by value and see of that fix it.
                https://github.com/iniside/ActionRPGGame - Action RPG Starter kit. Work in Progress. You can use it in whatever way you wish.

                Comment


                  #9
                  Good one too :-)
                  But with server rpc you have to use const ref for FStrings.
                  Anyway, the warnings don't depend on arguments, i have a lot of server rpc's in my code, some with arguments, some without, and they all give warnings since 4.7.
                  Cheers
                  Cedric

                  Comment


                    #10
                    Originally posted by uced View Post
                    Good one too :-)
                    But with server rpc you have to use const ref for FStrings.
                    Anyway, the warnings don't depend on arguments, i have a lot of server rpc's in my code, some with arguments, some without, and they all give warnings since 4.7.
                    Cheers
                    Cedric
                    I think we need to choch this up to a Preview build issue.
                    the rest of the C++ changes are coming for 4.7 so am guessing its due to that.

                    I whould report it on AnswerHub just in case.

                    Comment


                      #11
                      Might be an issue in 4.7 because your code seems good.

                      You can check on the other hand the source code and see how they are doing RPC call in 4.7

                      Comment


                        #12
                        I'm pretty sure this is because you've declared your function in the header file, already with the '_Implementation' suffix. You only do that in the .cpp and the compiler/VAX will automatically figure out what it's supposed to do.

                        If I'm right then you're getting the build error because it's adding _Implementation on again in the compilation process and it can't find that function. I'm guessing that in 4.7 UBT has been changed slightly to not bother checking if you've already added _Implementation on... maybe

                        Comment


                          #13
                          Hey all !

                          @WCode: yes, i am starting to think something like that. I was hoping for some official confirmation, just to know if this pb is worth the time i spend on it. Those warnings are annoying, i can't see my errors, ha ha !

                          @Elvince: good idea, i'll try to check that tonight

                          @TheJamsh: i don't think so. The initial code (see the initial post) was ok, the added _Implementation came later as tries to get rid of the warnings.

                          Cheers !

                          Cedric

                          Comment


                            #14
                            PS: i actually started with a answerhub question 3 days ago with no success, so i tried the forum.
                            https://answers.unrealengine.com/que...claration.html

                            Comment


                              #15
                              Originally posted by uced View Post
                              @TheJamsh: i don't think so. The initial code (see the initial post) was ok, the added _Implementation came later as tries to get rid of the warnings.
                              Ahh I see, my mistake. In that case I can't see an issue with it either then... Elvince & WCode have the right idea

                              Edit: Also... that's Answerhub for you :P I often double post here and on answerhub and usually the forum yields a better discussion about it (that's if answerhub even get's a response!), especially programming related things!

                              Comment

                              Working...
                              X