docs: Updated SyncVar docs

This commit is contained in:
Chris Langsenkamp 2020-02-23 02:48:21 -05:00
parent e1d1d41ed6
commit 25edcf0d41
2 changed files with 2 additions and 1 deletions

View File

@ -5,6 +5,7 @@
The hook attribute can be used to specify a function to be called when the SyncVar changes value on the client. This ensures that all clients receive the proper variables from other clients. The hook attribute can be used to specify a function to be called when the SyncVar changes value on the client. This ensures that all clients receive the proper variables from other clients.
- The Hook method must have a two parameters of the same type as the SyncVar property. One for the old value, one for the new value. - The Hook method must have a two parameters of the same type as the SyncVar property. One for the old value, one for the new value.
- The Hook is always called after the value was set. You don't need to set it yourself. - The Hook is always called after the value was set. You don't need to set it yourself.
- The Hook only fires for changed values, and changing a value in the inspector will not trigger an update.
Below is a simple example of assigning a random color to each player when they're spawned on the server. All clients will see all players in the correct colors, even if they join later. Below is a simple example of assigning a random color to each player when they're spawned on the server. All clients will see all players in the correct colors, even if they join later.

View File

@ -8,7 +8,7 @@ The state of SyncVars is applied to game objects on clients before `OnStartClien
SyncVars can use any [type supported by Mirror](../DataTypes.md). You can have up to 64 SyncVars on a single NetworkBehaviour script, including SyncLists (see next section, below). SyncVars can use any [type supported by Mirror](../DataTypes.md). You can have up to 64 SyncVars on a single NetworkBehaviour script, including SyncLists (see next section, below).
The server automatically sends SyncVar updates when the value of a SyncVar changes, so you do not need to track when they change or send information about the changes yourself. The server automatically sends SyncVar updates when the value of a SyncVar changes, so you do not need to track when they change or send information about the changes yourself. Changing a value in the inspector will not trigger an update.
> The [SyncVar hook](SyncVarHook.md) attribute can be used to specify a method to be called when the SyncVar changes value on the client. > The [SyncVar hook](SyncVarHook.md) attribute can be used to specify a method to be called when the SyncVar changes value on the client.