mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
docs: Document correct syncset initialization
This commit is contained in:
parent
8aadd245fd
commit
8fc939c044
@ -23,7 +23,7 @@ class Player : NetworkBehaviour {
|
||||
|
||||
class SyncSkillSet : SyncHashSet<string> {}
|
||||
|
||||
SyncSkillSet skills = new SyncSkillSet();
|
||||
readonly SyncSkillSet skills = new SyncSkillSet();
|
||||
|
||||
int skillPoints = 10;
|
||||
|
||||
@ -40,14 +40,25 @@ class Player : NetworkBehaviour {
|
||||
}
|
||||
```
|
||||
|
||||
You can also detect when a SyncHashSet changes. This is useful for refreshing your character in the client or determining when you need to update your database. Subscribe to the Callback event typically during `Start`, `OnClientStart` or `OnServerStart` for that. Note that by the time you subscribe, the set will already be initialized, so you will not get a call for the initial data, only updates.
|
||||
You can also detect when a SyncHashSet changes. This is useful for refreshing your character in the client or determining when you need to update your database.
|
||||
|
||||
Subscribe to the Callback event typically during `Start`, `OnClientStart` or `OnServerStart` for that.
|
||||
|
||||
<aside class="notice">
|
||||
Note that by the time you subscribe, the set will already be initialized, so you will not get a call for the initial data, only updates.
|
||||
</aside>
|
||||
|
||||
<aside class="notice">
|
||||
Note SyncSets must be initialized in the constructor, not in Startxxx(). You can make them readonly to ensure correct usage.
|
||||
</aside>
|
||||
|
||||
|
||||
```cs
|
||||
class Player : NetworkBehaviour
|
||||
{
|
||||
class SyncSetBuffs : SyncHashSet<string> {};
|
||||
|
||||
SyncSetBuffs buffs = new SyncSetBuffs();
|
||||
public readonly SyncSetBuffs buffs = new SyncSetBuffs();
|
||||
|
||||
// this will add the delegate on the client.
|
||||
// Use OnStartServer instead if you want it on the server
|
||||
|
Loading…
Reference in New Issue
Block a user