Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

[Beta 2] UNet weaver error for virtual methods

Discussion in '2017.1 Beta' started by Dizzy-Dalvin, Apr 26, 2017.

  1. Dizzy-Dalvin

    Dizzy-Dalvin

    Joined:
    Jul 4, 2013
    Posts:
    54
    In our project all UNet commands and RPCs (about 40 methods) are defined as empty virtual methods on base class NetworkPlayer and have implementation in derived classes: one for server project and two for client project (1st person and 3rd person players).

    Now when opening the project in 2017.1.0b2 I get the following error which weren't there in the first beta:
    Is this a breaking change or is this a bug?
     
    KyleOlsen likes this.
  2. MichalBUnity

    MichalBUnity

    Unity Technologies

    Joined:
    May 9, 2016
    Posts:
    18
    So overridden virtual functions have never worked with Commands and RPC functions, this error message was explicitly added for now to inform users to avoid overriding these type of functions.
     
  3. Dizzy-Dalvin

    Dizzy-Dalvin

    Joined:
    Jul 4, 2013
    Posts:
    54
    @MichalBUnity I don't think that's true. In our project they worked perfectly fine at least since 5.3 up to 5.6 and 2017.1.0b1.
     
    KyleOlsen likes this.
  4. MichalBUnity

    MichalBUnity

    Unity Technologies

    Joined:
    May 9, 2016
    Posts:
    18
    How do you guys invoke the command calls?

    Might be that i have missed a use-case and if that is the case i would very much like to see how you guys implement and invoke your Commands.
     
  5. Dizzy-Dalvin

    Dizzy-Dalvin

    Joined:
    Jul 4, 2013
    Posts:
    54
    Code (CSharp):
    1. public class Player : NetworkBehaviour
    2. {
    3.     ...
    4. }
    5.  
    6. public abstract class NetworkPlayer : Player
    7. {
    8.     ...
    9.     [Command] protected virtual void CmdSearchContent(string itemId, uint callbackId) { }
    10.     [ClientRpc] protected virtual void RpcSetDamageCoeff(float damageCoefficient) { }
    11.     ...
    12. }
    13.  
    14.  
    15. public class ServerPlayer : NetworkPlayer
    16. {
    17.     protected override void CmdSearchContent(string itemId, uint callbackId)
    18.     {
    19.         // server logic here
    20.     }
    21. }
    22.  
    23. public class ClientPlayer : Player
    24. {
    25.     protected override void RpcSetDamageCoeff(float damageCoefficient)
    26.     {
    27.         // 1st-person logic here
    28.     }
    29. }
    30.  
    31. public class ObservedPlayer : Player
    32. {
    33.     protected override void RpcSetDamageCoeff(float damageCoefficient)
    34.     {
    35.         // 3rd-person logic here
    36.     }
    37. }
    Then we invoke them as usual:
    Code (CSharp):
    1.     // on client
    2.     ...
    3.     Player.CmdSearchContent(operation.Item.Id, confirmId);
    4.     ...
    5.  
    6.     // on server
    7.     ...
    8.     RpcSetDamageCoeff(damageCoefficient);
    9.     ...
     
    KyleOlsen likes this.
  6. MichalBUnity

    MichalBUnity

    Unity Technologies

    Joined:
    May 9, 2016
    Posts:
    18
    Thanks for the information, and you are correct this would work for you guys. I will revert this change and instead update the documentation regarding Commands, RPCs and virtual functions to avoid issues while we work to make it safe for every inheritance use-case.

    I would recommend you to go back to 5.6 or 2017.1.0b1 for now, I'm sorry for the inconvenience this have caused. I'll get back to you when i know when the fix will be out.
     
  7. Dizzy-Dalvin

    Dizzy-Dalvin

    Joined:
    Jul 4, 2013
    Posts:
    54
    No worries, I've got a separate branch for testing out beta versions. Just trying to detect and report any issues as soon as possible, before they seep into main release.
     
    KyleOlsen likes this.
  8. Dizzy-Dalvin

    Dizzy-Dalvin

    Joined:
    Jul 4, 2013
    Posts:
    54
    This seems to be fixed in the latest beta (b4). The project compiles fine now.
     
    MichalBUnity and KyleOlsen like this.