Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Unity Multiplayer How do you use SetDirtyBit ?

Discussion in 'Connected Games' started by Paradoks, Jul 9, 2018.

  1. Paradoks

    Paradoks

    Joined:
    Oct 13, 2009
    Posts:
    408
    Hi,

    It is a pretty newbie question, i don't really understand how to use it as the manual don't say much.
    What is this parameter "Bit mask to set" ?
    Why sometimes people put parametters sometimes not ?

    thx for you answers.
     
  2. Paradoks

    Paradoks

    Joined:
    Oct 13, 2009
    Posts:
    408
    @aabramychev
    Someone from unity at least please, you make a tool, and dont let informations on manual.
     
  3. aabramychev

    aabramychev

    Unity Technologies

    Joined:
    Jul 17, 2012
    Posts:
    547
    I'm sorry, but I don't understand what are you talking about. What SetDirtyBit do you want to set and where? :(
     
  4. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    2,673
    SetDirtyBits sets NetworkBehaviour.syncVarDirtyBits:
    upload_2018-7-21_13-13-11.png

    UNET only serializes your components if at least one of them is dirty.

    If you are wondering what this magic is for: let's say you have 3 variables in your Player script that you want to sync over the network. OnSerialize gets called, then you sync all 3 of them. OnSerialize gets called again, but maybe only 1 of them changed, so there's no point in syncing all 3 of them again, or you'd waste bandwidth. You only want to sync the changed one. So in order to know which things changed, you always also send the dirty bit mask. For example, if the first bit is 1, then your first value changed. If the second bit is 1, then your second value changed, etc.
     
  5. Paradoks

    Paradoks

    Joined:
    Oct 13, 2009
    Posts:
    408
    That's a good explanation thx.
    But how do you practically use it ?
    Let's take this scenario:

    Code (CSharp):
    1.  
    2.  
    3. [SyncVar]
    4. public int hp= 100;
    5.  
    6. [SyncVar]
    7. public int mp= 100;
    8.  
    9. [SyncVar]
    10. public int gold= 100;
    11.  
    12. void Start(){
    13.  
    14.     ChangeHp(9999);
    15. }
    16.  
    17. void ChangeHp(int newHp){
    18.  
    19.     hp = newHp;
    20. }
    21.  
    All the syncVars should be sent right ?
    So now how do you change only the hp one ? before the "all sync" get triggered ?