Skip to content

Commit beb08e8

Browse files
authored
fix: adding null checks when accessing NetworkBehaviour (#3011)
* adding null checks when accessing NetworkBehaviour * updating PR number in changelog
1 parent 231b36d commit beb08e8

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
1212

1313
### Fixed
1414

15+
- Fixed issue by adding null checks in `NetworkVariableBase.CanClientRead` and `NetworkVariableBase.CanClientWrite` methods to ensure safe access to `NetworkBehaviour`. (#3011)
1516
- Fixed issue using collections within `NetworkVariable` where the collection would not detect changes to items or nested items. (#3005)
1617
- Fixed issue where `List`, `Dictionary`, and `HashSet` collections would not uniquely duplicate nested collections. (#3005)
1718
- 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. (#2999)

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

+10
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ public virtual bool IsDirty()
243243
/// <returns>Whether or not the client has permission to read</returns>
244244
public bool CanClientRead(ulong clientId)
245245
{
246+
if (!m_NetworkBehaviour)
247+
{
248+
return false;
249+
}
250+
246251
switch (ReadPerm)
247252
{
248253
default:
@@ -260,6 +265,11 @@ public bool CanClientRead(ulong clientId)
260265
/// <returns>Whether or not the client has permission to write</returns>
261266
public bool CanClientWrite(ulong clientId)
262267
{
268+
if (!m_NetworkBehaviour)
269+
{
270+
return false;
271+
}
272+
263273
switch (WritePerm)
264274
{
265275
default:

0 commit comments

Comments
 (0)