-
-
Notifications
You must be signed in to change notification settings - Fork 307
Fields
The Network Object is a variable found in the classes that were generated from using the Network Contract Wizard (NCW). When you create a field in the Network Contract Wizard (NCW) for a generated type, then it will be added as a property of that generated type. Below are the currently supported types of fields allowed in a network object field.
Field | Size |
---|---|
byte | 8 bits |
sbyte | 8 bits |
short | 16 bits |
ushort | 16 bits |
int | 32 bits |
uint | 32 bits |
long | 64 bits |
ulong | 64 bits |
float | 32 bits |
double | 64 bits |
char | 8 bits |
Vector | 96 bits |
Vector2 | 64 bits |
Vector3 | 96 bits |
Vector4 | 128 bits |
Quaternion | 128 bits |
Color | 128 bits |
When you generate a class it will be generated with a networkObject variable. This variable has all of the fields that you described in the Network Contract Wizard (NCW) built into it. For example, if you created a field in the Network Contract Wizard (NCW) that was named position and was selected to be a VECTOR3 then you will have access to it by doing networkObject.position. One thing that you will notice when doing this is that this field is actually a C# property, but we will explain this momentarily.
On some fields (such as VECTOR3) you will notice that it has a greyed out button labeled interpolate. If you were to click this, it will turn on interpolation for this field. You can set the interpolation time by assigning the text input field to the right of the button once it is active, default is 0.15. If you are not familiar with interpolation, basically when we send messages across the network we are dealing with millisecond gaps of information, this will cause objects to seem as though they were teleporting or lagging. By using interpolation, you can smooth out these movements to look more natural.
You need to be aware that only the owner can set a field's value. If you try and set the value on a non-owner then the value will be set only locally and will not be propagated to other clients over the network.
This behaviour can be overridden to allow the server to also set the field by setting the AuthorityUpdateMode
to true for the network object on the server. BEWARE, this can cause race conditions in data transfer, so only use as a last resort!
You can change the interval at which fields are synchronized over the network using
networkObject.UpdateInterval = TIME_MILLISECONDS;
You can also have Fields only sync when in proximity
networkObject.Networker.ProximityDistance = DISTANCE;
networkObject.setProximityFields(true, MODE);
MODES |
---|
Receivers.AllProximity |
Receivers.OthersProximity |
Receivers.AllProximityGrid |
Receivers.OthersProximityGrid |
Refer to this PR for more info.
What is going on behind the scenes? Well let's start with where we left off in the last section on how the fields are actually properties. These properties have a getter/setter on each one. The getter will simply return a private field in the generated network object class; however, the setter does a few more actions. When you assign the value of the property, the setter will first set the private field to the value specified. Next a dirty flag will be set to tell the network to syndicate the change for that variable on the next network update for this object. What this dirty flag allows is for FNR to be able to only pick fields that have changed and send those across the network. This reduces the amount of data being sent by a lot depending on how often other variables are updated.
Getting Started
Network Contract Wizard (NCW)
Remote Procedure Calls (RPCs)
Unity Integration
Basic Network Samples
Scene Navigation
Master Server
Netcoding Design Patterns
Troubleshooting
Miscellaneous
-
Connection Cycle Events
-
Rewinding
-
Network Logging
-
Working with Multiple Sockets
-
Modify Master and Standalone servers
-
NAT Hole Punching
-
UDP LAN Discovery
-
Offline Mode
-
Ping Pong
-
Lobby System
-
Upgrading Forge Remastered to Develop branch or different version
-
Forge Networking Classic to Remastered Migration Guide
-
Script to easily use Forge Networking from sources
-
Run Two Unity Instances with Shared Assets for Easiest Dedicated Client Workflow