Skip to content

refactor: Remove SIPTransport and replace it with UnityTransport #1870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
744ea2b
delete `SIPTransport` & `SIPTransportTests`
0xFA11 Apr 4, 2022
be93240
fix compile errors
0xFA11 Apr 4, 2022
0e27cb9
fix
NoelStephensUnity Apr 11, 2022
87d9615
fix
NoelStephensUnity Apr 11, 2022
df94893
fix
NoelStephensUnity Apr 12, 2022
72ee0b3
fix
NoelStephensUnity Apr 12, 2022
8981be6
fix
NoelStephensUnity Apr 12, 2022
c59eaf6
Merge branch 'develop' into refactor/kill-sip-use-utp
NoelStephensUnity Apr 12, 2022
388d3b0
fix
NoelStephensUnity Apr 12, 2022
7609c35
fix
NoelStephensUnity Apr 12, 2022
5cd33f3
fix
NoelStephensUnity Apr 12, 2022
cdc68fd
Fix - NetworkSceneManager
NoelStephensUnity Apr 12, 2022
a9aaf6d
Fix - NetcodeIntegrationTest
NoelStephensUnity Apr 12, 2022
87f8154
Fix - ClientOnlyConnectionTests
NoelStephensUnity Apr 12, 2022
cd8c589
Fix - DisconnectTests
NoelStephensUnity Apr 12, 2022
3d3421f
fix - NetworkObjectOwnershipTests
NoelStephensUnity Apr 12, 2022
9d03654
fix - NetworkSceneManagerEventDataPoolTest
NoelStephensUnity Apr 12, 2022
74e75b2
fix - NetworkSceneManagerSeneVerification
NoelStephensUnity Apr 12, 2022
ea87ed3
style
NoelStephensUnity Apr 12, 2022
0325622
style
NoelStephensUnity Apr 12, 2022
2503736
update MTT-3016
NoelStephensUnity Apr 12, 2022
8f2ac41
Update CHANGELOG.md
NoelStephensUnity Apr 12, 2022
e0f7fa7
Update CHANGELOG.md
NoelStephensUnity Apr 12, 2022
4a23b77
fix - tools
NoelStephensUnity Apr 12, 2022
2d816c1
Update com.unity.netcode.gameobjects/CHANGELOG.md
NoelStephensUnity Apr 12, 2022
9c80c35
Update com.unity.netcode.gameobjects/CHANGELOG.md
NoelStephensUnity Apr 12, 2022
22afc78
fix
NoelStephensUnity Apr 12, 2022
dcca79c
fix - console - ps4
NoelStephensUnity Apr 13, 2022
d850635
Merge branch 'develop' into refactor/kill-sip-use-utp
NoelStephensUnity Apr 13, 2022
1549c2f
revert
NoelStephensUnity Apr 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Changed

- Changed `NetcodeIntegrationTestHelpers` to use `UnityTransport` (#1870)
- Updated `UnityTransport` dependency on `com.unity.transport` to 1.0.0 (#1849)

### Removed

- Removed `SIPTransport` (#1870)
- Removed `SnapshotSystem` (#1852)
- Removed `com.unity.modules.animation`, `com.unity.modules.physics` and `com.unity.modules.physics2d` dependencies from the package (#1812)
- Removed `com.unity.collections` dependency from the package (#1849)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,9 @@ private bool CanStart(StartType type)
return false;
}

if (NetworkConfig.ConnectionApproval)
// Only if it is starting as a server or host do we need to check this
// Clients don't invoke the ConnectionApprovalCallback
if (NetworkConfig.ConnectionApproval && type != StartType.Client)
{
if (ConnectionApprovalCallback == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1746,7 +1746,9 @@ private void HandleServerSceneEvent(uint sceneEventId, ulong clientId)
// NetworkObjects
m_NetworkManager.InvokeOnClientConnectedCallback(clientId);

if (sceneEventData.ClientNeedsReSynchronization() && !DisableReSynchronization)
// Check to see if the client needs to resynchronize and before sending the message make sure the client is still connected to avoid
// a potential crash within the MessageSystem (i.e. sending to a client that no longer exists)
if (sceneEventData.ClientNeedsReSynchronization() && !DisableReSynchronization && m_NetworkManager.ConnectedClients.ContainsKey(clientId))
Comment on lines +1749 to +1751
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
sceneEventData.SceneEventType = SceneEventType.ReSynchronize;
SendSceneEventData(sceneEventId, new ulong[] { clientId });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ public static void DeregisterNetworkObject(ulong localClientId, ulong networkObj
protected const uint k_DefaultTickRate = 30;
protected abstract int NumberOfClients { get; }

/// <summary>
/// Set this to false to create the clients first.
/// Note: If you are using scene placed NetworkObjects or doing any form of scene testing and
/// get prefab hash id "soft synchronization" errors, then set this to false and run your test
/// again. This is a work-around until we can resolve some issues with NetworkManagerOwner and
/// NetworkManager.Singleton.
/// </summary>
Comment on lines +82 to +88
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mind elaborating a little more? what's going on here?

Copy link
Collaborator Author

@NoelStephensUnity NoelStephensUnity Apr 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a little complicated, but it has to do with our integration tests running in the same thread, how we populate newly loaded (not yet "spawned") in-scene placed NetworkObjects, and NetworkObject.NetworkManager referencing NetworkManager.Singleton if NetworkObject.NetworkManagerOwner is null.

  • Same Thread: In several places we check to make sure the NetworkObject.NetworkManager is the "right one" for the NetworkManager context (i.e. NetworkObject.NetworkManager == NetworkManager)
  • Populating In-Scene Objects: This checks to make sure the NetworkSceneManager.m_NetworkManager is the same as the NetworkObject.NetworkManager before adding it to the ScenePlacedObjects list.
  • Default NetworkManager: This happens to be NetworkManager.Singleton that is set upon the first NetworkManager being instantiated.

So, under some conditions you might want NetworkManager.Singleton to be the server and under other conditions you might want it to be a client. If you are loading a scene with in-scene placed NetworkObjects, then you will want the NetworkManager.Singleton to be the first client instantiated in order to properly synchronize/find the in-scene placed NetworkObjects (which are loaded by the server and not loaded by the client since they share the same scene space).

If you want more details feel free to DM me in slack... really we need to handle in-scene placed NetworkObjects better... like that "pre-rfc" document outlines.

protected bool m_CreateServerFirst = true;

public enum NetworkManagerInstatiationMode
{
PerTest, // This will create and destroy new NetworkManagers for each test within a child derived class
Expand Down Expand Up @@ -108,8 +117,6 @@ public enum HostOrServer
protected bool m_UseHost = true;
protected int m_TargetFrameRate = 60;

protected NetcodeIntegrationTestHelpers.InstanceTransport m_NetworkTransport = NetcodeIntegrationTestHelpers.InstanceTransport.SIP;

private NetworkManagerInstatiationMode m_NetworkManagerInstatiationMode;

private bool m_EnableVerboseDebug;
Expand Down Expand Up @@ -252,7 +259,7 @@ protected void CreateServerAndClients(int numberOfClients)
CreatePlayerPrefab();

// Create multiple NetworkManager instances
if (!NetcodeIntegrationTestHelpers.Create(numberOfClients, out NetworkManager server, out NetworkManager[] clients, m_TargetFrameRate, m_NetworkTransport))
if (!NetcodeIntegrationTestHelpers.Create(numberOfClients, out NetworkManager server, out NetworkManager[] clients, m_TargetFrameRate, m_CreateServerFirst))
{
Debug.LogError("Failed to create instances");
Assert.Fail("Failed to create instances");
Expand Down Expand Up @@ -558,6 +565,7 @@ protected void DestroySceneNetworkObjects()
}
if (CanDestroyNetworkObject(networkObject))
{
networkObject.NetworkManagerOwner = m_ServerNetworkManager;
// Destroy the GameObject that holds the NetworkObject component
Object.DestroyImmediate(networkObject.gameObject);
}
Expand Down Expand Up @@ -668,6 +676,7 @@ protected GameObject CreateNetworkObjectPrefab(string baseName)
var gameObject = new GameObject();
gameObject.name = baseName;
var networkObject = gameObject.AddComponent<NetworkObject>();
networkObject.NetworkManagerOwner = m_ServerNetworkManager;
NetcodeIntegrationTestHelpers.MakeNetworkObjectTestPrefab(networkObject);
var networkPrefab = new NetworkPrefab() { Prefab = gameObject };
m_ServerNetworkManager.NetworkConfig.NetworkPrefabs.Add(networkPrefab);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@ public void OnAfterHandleMessage<T>(ref T message, ref NetworkContext context) w

public static List<NetworkManager> NetworkManagerInstances => s_NetworkManagerInstances;

public enum InstanceTransport
{
SIP,
UTP
}

internal static IntegrationTestSceneHandler ClientSceneHandler = null;

/// <summary>
Expand Down Expand Up @@ -162,20 +156,32 @@ public static void RegisterHandlers(NetworkManager networkManager, bool serverSi
}
}

/// <summary>
/// Create the correct NetworkTransport, attach it to the game object and return it.
/// Default value is SIPTransport.
/// </summary>
internal static NetworkTransport CreateInstanceTransport(InstanceTransport instanceTransport, GameObject go)
public static NetworkManager CreateServer()
{
switch (instanceTransport)
// Create gameObject
var go = new GameObject("NetworkManager - Server");

// Create networkManager component
var server = go.AddComponent<NetworkManager>();
NetworkManagerInstances.Insert(0, server);

// Create transport
var unityTransport = go.AddComponent<UnityTransport>();
// We need to increase this buffer size for tests that spawn a bunch of things
unityTransport.MaxPayloadSize = 256000;
unityTransport.MaxSendQueueSize = 1024 * 1024;

// Allow 4 connection attempts that each will time out after 500ms
unityTransport.MaxConnectAttempts = 4;
unityTransport.ConnectTimeoutMS = 500;

// Set the NetworkConfig
server.NetworkConfig = new NetworkConfig()
{
case InstanceTransport.SIP:
return go.AddComponent<SIPTransport>();
default:
case InstanceTransport.UTP:
return go.AddComponent<UnityTransport>();
}
// Set transport
NetworkTransport = unityTransport
};
return server;
}

/// <summary>
Expand All @@ -185,24 +191,22 @@ internal static NetworkTransport CreateInstanceTransport(InstanceTransport insta
/// <param name="server">The server NetworkManager</param>
/// <param name="clients">The clients NetworkManagers</param>
/// <param name="targetFrameRate">The targetFrameRate of the Unity engine to use while the multi instance helper is running. Will be reset on shutdown.</param>
public static bool Create(int clientCount, out NetworkManager server, out NetworkManager[] clients, int targetFrameRate = 60, InstanceTransport instanceTransport = InstanceTransport.SIP)
/// <param name="serverFirst">This determines if the server or clients will be instantiated first (defaults to server first)</param>
public static bool Create(int clientCount, out NetworkManager server, out NetworkManager[] clients, int targetFrameRate = 60, bool serverFirst = true)
{
s_NetworkManagerInstances = new List<NetworkManager>();
CreateNewClients(clientCount, out clients, instanceTransport);

// Create gameObject
var go = new GameObject("NetworkManager - Server");
server = null;
if (serverFirst)
{
server = CreateServer();
}

// Create networkManager component
server = go.AddComponent<NetworkManager>();
NetworkManagerInstances.Insert(0, server);
CreateNewClients(clientCount, out clients);

// Set the NetworkConfig
server.NetworkConfig = new NetworkConfig()
if (!serverFirst)
{
// Set transport
NetworkTransport = CreateInstanceTransport(instanceTransport, go)
};
server = CreateServer();
}

s_OriginalTargetFrameRate = Application.targetFrameRate;
Application.targetFrameRate = targetFrameRate;
Expand All @@ -215,7 +219,7 @@ public static bool Create(int clientCount, out NetworkManager server, out Networ
/// </summary>
/// <param name="clientCount">The amount of clients</param>
/// <param name="clients"></param>
public static bool CreateNewClients(int clientCount, out NetworkManager[] clients, InstanceTransport instanceTransport = InstanceTransport.SIP)
public static bool CreateNewClients(int clientCount, out NetworkManager[] clients)
{
clients = new NetworkManager[clientCount];
var activeSceneName = SceneManager.GetActiveScene().name;
Expand All @@ -226,11 +230,14 @@ public static bool CreateNewClients(int clientCount, out NetworkManager[] client
// Create networkManager component
clients[i] = go.AddComponent<NetworkManager>();

// Create transport
var unityTransport = go.AddComponent<UnityTransport>();

// Set the NetworkConfig
clients[i].NetworkConfig = new NetworkConfig()
{
// Set transport
NetworkTransport = CreateInstanceTransport(instanceTransport, go)
NetworkTransport = unityTransport
};
}

Expand Down Expand Up @@ -273,7 +280,10 @@ public static void Destroy()
// Destroy the network manager instances
foreach (var networkManager in NetworkManagerInstances)
{
Object.DestroyImmediate(networkManager.gameObject);
if (networkManager.gameObject != null)
{
Object.Destroy(networkManager.gameObject);
}
}

NetworkManagerInstances.Clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using UnityEngine;
using NUnit.Framework;
using Unity.Netcode.Transports.UTP;

namespace Unity.Netcode.TestHelpers.Runtime
{
Expand Down Expand Up @@ -67,11 +68,7 @@ public static bool StartNetworkManager(out NetworkManager networkManager, Networ

Debug.Log($"{nameof(NetworkManager)} Instantiated.");

// NOTE: For now we only use SIPTransport for tests until UnityTransport
// has been verified working in nightly builds
// TODO-MTT-2486: Provide support for other transports once tested and verified
// working on consoles.
var sipTransport = NetworkManagerGameObject.AddComponent<SIPTransport>();
var unityTransport = NetworkManagerGameObject.AddComponent<UnityTransport>();
if (networkConfig == null)
{
networkConfig = new NetworkConfig
Expand All @@ -81,7 +78,7 @@ public static bool StartNetworkManager(out NetworkManager networkManager, Networ
}

NetworkManagerObject.NetworkConfig = networkConfig;
NetworkManagerObject.NetworkConfig.NetworkTransport = sipTransport;
NetworkManagerObject.NetworkConfig.NetworkTransport = unityTransport;

// Starts the network manager in the mode specified
StartNetworkManagerMode(managerMode);
Expand Down

This file was deleted.

Loading