Netcode for GameObjects
Last updated
Last updated
The Status Effect Framework now supports Unity's Netcode for GameObjects package. This means it will be possible to synchronize Status Effects from servers to clients with ease. Just note that the system is server authoritative, and all logic related to StatusVariables should ideally only run on the server.
Netcode for GameObjects must use version 1.8 or newer and the Addressables package must also be used!
To begin syncing Status Effects, simply replace any StatusManagers with a NetworkStatusManager. Functionally the NetworkStatusManager is the same as the regular StatusManager exept that the key difference is in how adding new Status Effects will work. Instead of passing in the StatusEffectData to create a new StatusEffect with, the AddStatusEffect method will take in an AssetReferenceT<ScriptableObject> and return an awaitable task (either Awaitable or UniTask) that outputs the created StatusEffect. This is because Scriptable Objects cannot be sent directly over the network, so the asset GUID reference is sent over it instead.
In addition to adding the NetworkStatusManager, make sure that the GameObject it is added to also has a NetworkObject component. Status Effects will not sync if you do not add this.
In addition to the new NetworkStatusManager there are also a few classes that can replace the previous non-networked StatusVariables: NetworkStatusFloat, NetworkStatusInt, and NetworkStatusBool. The only difference between the NetworkStatusVariable and regular StatusVariables is that the base value and sign protected value will automatically sync across the network. There is a caveat to this however. Since StatusVariables are capable of being nested inside other classes or in arrays and lists, NetworkStatusVariables cannot. Similar to the base NetworkVariable class, all NetworkStatusVariables must be in a NetworkBehaviour and not nested within anything. Again, make sure that the GameObject with the NetworkBehaviour also has a NetworkObject component.
Good to know: If you still want to use non-networked StatusVariables, you can still use the NetworkStatusManager in its SetManager method.
Thats it! If you have other questions or find any bugs feel free to send me a message on Discord or add it to the issue tracker on GitHub.