Skip to content

Commit a7dab56

Browse files
fix: NullReferenceException caused when unsubscribing on session removal [MTTB-1161] (#905)
* moving unsubscription to when session not null * changelog addition
1 parent 911643f commit a7dab56

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

Assets/Scripts/UnityServices/Sessions/MultiplayerServicesFacade.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void BeginTracking()
7878
if (!m_IsTracking)
7979
{
8080
m_IsTracking = true;
81-
SubscribeToJoinedSessionAsync();
81+
SubscribeToJoinedSession();
8282
}
8383
}
8484

@@ -91,11 +91,11 @@ public void EndTracking()
9191
if (m_IsTracking)
9292
{
9393
m_IsTracking = false;
94-
UnsubscribeFromJoinedSessionAsync();
9594
}
9695

9796
if (CurrentUnitySession != null)
9897
{
98+
UnsubscribeFromJoinedSession();
9999
if (m_LocalUser.IsHost)
100100
{
101101
DeleteSessionAsync();
@@ -232,7 +232,7 @@ void ResetSession()
232232
// no need to disconnect Netcode, it should already be handled by Netcode's callback to disconnect
233233
}
234234

235-
void SubscribeToJoinedSessionAsync()
235+
void SubscribeToJoinedSession()
236236
{
237237
CurrentUnitySession.Changed += OnSessionChanged;
238238
CurrentUnitySession.StateChanged += OnSessionStateChanged;
@@ -244,7 +244,7 @@ void SubscribeToJoinedSessionAsync()
244244
CurrentUnitySession.SessionPropertiesChanged += OnSessionPropertiesChanged;
245245
}
246246

247-
void UnsubscribeFromJoinedSessionAsync()
247+
void UnsubscribeFromJoinedSession()
248248
{
249249
CurrentUnitySession.Changed -= OnSessionChanged;
250250
CurrentUnitySession.StateChanged -= OnSessionStateChanged;

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
5959
* Changed the way MeleeAction selects a target when there are multiple targets to collide with. The target with the highest GetTotalDamage value (mentioned above) will be selected.
6060
* Fixed a visual issue where a selected party member's party HUD slot would be displayed as selected (green) when the same or new party member joins the session in-game (#899)
6161
* Fixed Render Graph API compatibility mode warning and switched active input handling settings to "both" for removing InvalidOperationException (#901)
62+
* Fixed error logged when unsubscribing from Session events when removed from a Session (#905)
6263

6364
## [2.5.0] - 2024-04-18
6465

0 commit comments

Comments
 (0)