unity-game-engineunity3d-unet

Unity NetworkTransform, force update every Frame?


On a purposed LAN setup, I want Unity's NetworkTransform to simply send every single frame. (Mode is "Sync Transform", not rigidbody, etc.)

I'm wondering how to do this .. if you just set the send rate to 0.00001 will it in fact do it every frame that the object is moving?

(The Inspector interface only allows up to 29Hz, simply set it in code if you want smaller values.)

I was also thinking something like on a script......

 void Update() { .. SetDirtyBit( ? ); }

would that do it?

(And, what do you use as a bitmask there?)

It really takes forever to determine this sort of thing experimentally. Obviously Unity's doco is a joke. And I couldn't google anyone who'd already figured it. Any experience in this?


Secondly...

Further information. We did some experiments and indeed if you set it to a very small value, it does seem to sync the NetworkTransform every single frame.

(Of course, it doesn't bother sending if it has not moved, as @Programmer points out below.)

H O W E V E R this does not produce smooth results for kinematic objects or camera positions. I don't know why; it has to do with the Update loop and exactly when the change takes place. But what you get is a "very fine jitter".


Thirdly...

I did an experiment, simply using Commands and Rpcs, to send some information every frame (actually from one client to another).

I specifically used a purpose solo ethernet network and the apps do little or nothing other than send the info every frame (ie "manually" just using Command/Rpc), ie on Update().

In fact, it still drops many frames, it's often not sent. (Let's say, it misses 10 or 20 in 10 seconds worth.)

Good grief!

Do not bother doing this if you need some info sent "every frame", say on a LAN system.


Solution

  • In the Unity Docs It says

    If sendInterval is zero, updates will be sent at the end of the frame when dirty bits are set for that script. Note that setting the value of a SyncVar will automatically set dirty bits.

    So you could use your own script using NetworkSettings

    using UnityEngine.Networking;
    
    [NetworkSettings(channel = 1, sendInterval = 0.0f)]
    class MyScript : NetworkBehaviour
    {
        [SyncVar]
        int value;
    }
    

    However SyncVar only works Server -> Client.

    But you can use SetDirtyBit to manually set the behaviour dirty.


    Or you probably could also use InvokeSyncEvent to synchronize some values directly.


    Here I found a bit more information on Dirty bits.