Search Unity

explaination of networkSyncAnim

Discussion in 'Multiplayer' started by llavigne, Mar 4, 2008.

  1. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    In the networkSyncAnimation c# script of the networking sample, I see the lines:

    Code (csharp):
    1.  
    2.         else
    3.         {
    4.             char ani = (char)0;
    5.             stream.Serialize(ref ani);
    6.            
    7.             currentAnimation = (AniStates)ani;
    8.         }  
    9.  
    do we set anim at "0" only to initialize a reference variable ani so the next line can fill it with meaningful stuff?

    Also how does the script knows that isWriting is true or false? is it what network view does through the onserializenetworkview ?


    Finally the character has multiple network views and in this script i don't see a different network view id # ...
     
  2. larus

    larus

    Unity Technologies

    Joined:
    Oct 12, 2007
    Posts:
    280
    Yes, thats the idea. Serialize() takes a reference to the variable and hopefully puts something meaningful in it.

    isWriting is a property of the BitStream which is passed into the OnSerializeNetworkView function. Then the BitStream.isWriting property indicates if the bitstream is being sent over the network (isWriting=true) or being received (isWriting=false).

    This script is attached to a specific one of those network views which has a specific view ID number. You can print out networkView.viewID inside the script, but that should also be plain to see in the editor.
     
  3. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    All is now crystal clear and RPCs just raised their hands as I was trying to state synchronize a bunch of stuff which happened < once per second.

    Since we can't have State sync at a different frequency, isn't it smarter to RPC changes in health and other things which don't occur continuously ?
     
  4. larus

    larus

    Unity Technologies

    Joined:
    Oct 12, 2007
    Posts:
    280
    Yes, health changes, and such notifications are best handled through RPCs.

    You can actually change the frequency of updates through Network.sendRate. This affects how often state is synchronized on all network views. If you use ReliableDiffCompressed network views then it only synchronizes when something changes, which can be a completely different rate than the sendRate but never more frequently.
     
  5. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    It changes for the entire game, not just a selected networkView - I know we spoke about this, but since I'm planning long term, will it be added in the near future ?