Describe what has been changed, any new features or bug fixes
switched our "already connected" logic to using a reference to a MonoBehaviour instead of just a bool. MonoBehaviours are typically destroyed when a scene reload happens and in this case we'll want to allow developers to spawn a new SpacetimeDBNetworkManager if the previous one has been destroyed.
API
This is not an API break.
[ ] This is an API breaking change to the SDK
If the API is breaking, please state below what will break
Requires SpacetimeDB PRs
List any PRs here that are required for this SDK change to work
Testing
Write instructions for a test that you performed for this PR
[x] Checkout the SpacetimeDBCircleGame project
[x] Remove SpacetimeDB package and add a new one: https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk.git#jdetter-fix-reconnection-logic
[x] Add a simple function to the GameManager which reloads the scene in order to cause a reconnection:
private void Start()
{
// add this to the bottom of start
StartCoroutine(Reconnect());
}
public IEnumerator Reconnect()
{
yield return new WaitForSeconds(3.0f);
// Reload the scene to cause a reconnection
UnityEngine.SceneManagement.SceneManager.LoadScene("Scenes/SampleScene");
}
Previously, before this PR you would end up with:
Unhandled log message: '[Exception] InvalidOperationException: SpacetimeDBNetworkManager is a singleton and should only be attached once.'. Use UnityEngine.TestTools.LogAssert.Expect
Description of Changes
Describe what has been changed, any new features or bug fixes
MonoBehaviour
instead of just a bool.MonoBehaviour
s are typically destroyed when a scene reload happens and in this case we'll want to allow developers to spawn a newSpacetimeDBNetworkManager
if the previous one has been destroyed.API
This is not an API break.
If the API is breaking, please state below what will break
Requires SpacetimeDB PRs
List any PRs here that are required for this SDK change to work
Testing
Write instructions for a test that you performed for this PR
https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk.git#jdetter-fix-reconnection-logic
public IEnumerator Reconnect() { yield return new WaitForSeconds(3.0f); // Reload the scene to cause a reconnection UnityEngine.SceneManagement.SceneManager.LoadScene("Scenes/SampleScene"); }
Unhandled log message: '[Exception] InvalidOperationException: SpacetimeDBNetworkManager is a singleton and should only be attached once.'. Use UnityEngine.TestTools.LogAssert.Expect