Skip to content

Commit 285e307

Browse files
authored
fix: adding null checks when accessing NetworkBehaviour for develop 2.0.0 (#3012)
* adding null checks when accessing NetworkBehaviour * updating PR number in changelog
1 parent 503dd15 commit 285e307

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
1414

1515
### Fixed
1616

17+
- Fixed issue by adding null checks in `NetworkVariableBase.CanClientRead` and `NetworkVariableBase.CanClientWrite` methods to ensure safe access to `NetworkBehaviour`. (#3012)
1718
- Fixed issue where `FixedStringSerializer<T>` was using `NetworkVariableSerialization<byte>.AreEqual` to determine if two bytes were equal causes an exception to be thrown due to no byte serializer having been defined. (#3009)
1819
- Fixed Issue where a state with dual triggers, inbound and outbound, could cause a false layer to layer state transition message to be sent to non-authority `NetworkAnimator` instances and cause a warning message to be logged. (#3008)
1920
- Fixed issue using collections within `NetworkVariable` where the collection would not detect changes to items or nested items. (#3004)

com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@ public virtual bool IsDirty()
264264
/// <returns>Whether or not the client has permission to read</returns>
265265
public bool CanClientRead(ulong clientId)
266266
{
267+
if (!m_NetworkBehaviour)
268+
{
269+
return false;
270+
}
271+
267272
// When in distributed authority mode, everyone can read (but only the owner can write)
268273
if (m_NetworkManager != null && m_NetworkManager.DistributedAuthorityMode)
269274
{
@@ -286,6 +291,11 @@ public bool CanClientRead(ulong clientId)
286291
/// <returns>Whether or not the client has permission to write</returns>
287292
public bool CanClientWrite(ulong clientId)
288293
{
294+
if (!m_NetworkBehaviour)
295+
{
296+
return false;
297+
}
298+
289299
switch (WritePerm)
290300
{
291301
default:

0 commit comments

Comments
 (0)