Search Unity

SyncVar Polymorphism Issue

Discussion in 'Multiplayer' started by BrandonJ, Feb 11, 2016.

  1. BrandonJ

    BrandonJ

    Joined:
    Sep 17, 2013
    Posts:
    3
    I ran into an issue with SyncVars which use polymorphism the other day and made a sample project to show the issue. I have also filed a bug report but put it up on here to hopefully have it fixed more quickly and help anyone having similar issues. Below is the basic description of the issue, as well as steps to reproduce the issue using the attached sample project.

    Class A - Inherits from NetworkBehaviour, Has a SyncVar
    Class B - Inherits from Class A, Has a different SyncVar
    Object A - Has both Class A and Class B attached to it.

    Upon updating a SyncVar on Class B, the UnityProfiler picks up the network transmission from the server to the client for Class B and the client picks up said transmission for Class B. This is completely normal behaviour.

    However, upon updating the SyncVar on Class A, the UnityProfiler picks up the the network transmission from the server to the client for Class A and the the client picks up a transmissions for Class A AND Class B. This is not normal behaviour. The effect is compounded upon adding additional Class B scripts to the object. Every time ANY SyncVar is updated on ANY script on an object containing the Class B script, EVERY Class B script is updated on the UnityProfiler.

    I came across this issue during natural testing and created a small sample project to show this bug. I will note that I did notice a rather large performance hit while testing this so I don't think it is simply a UnityProfiler visual bug.

    Follow the steps below to reproduce:

    1. Unzip the attached file.
    2. Open both the server and client Unity Projects.
    3. Open the UnityProfiler for both the client and server. Make sure that the NetworkOperation profiler is open for both UnityProfilers.
    4. Open the _entry scenes on both the client and server projects from the Assets/Scenes folders.
    5. Run both the client and server projects.
    6. Press the Server Only button for the server and the Client button for the client.
    7. On the server, pressing 'Q' will update the SyncVar on the PlayerObject for the "Class A" scripts as seen in the description above.

    Upon updating this SyncVar, you will see that the server has a single packet sent out Updating the SyncVarTest(Class A) script. The client UnityProfiler has recieved a packet for BOTH the SyncVarTest(Class A) and the SyncVarTest_InheritedWithSyncVar(Class B) scripts. There is a third class SyncVarTest_InheritedWithoutSyncVar(Class C) that inherits from Class A but does not have its own SyncVar. Class C has no issue and behaves normally. The issue only happens on classes which have inherited from another class containing a SyncVar that also contain SyncVars themselves.
     

    Attached Files: