docs.unity3d.com
    Show / Hide Table of Contents

    Class NetcodeIntegrationTestHelpers

    Provides helpers for running multi instance tests.

    Inheritance
    Object
    NetcodeIntegrationTestHelpers
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Unity.Netcode.TestHelpers.Runtime
    Syntax
    public static class NetcodeIntegrationTestHelpers

    Fields

    DefaultMinFrames

    Declaration
    public const int DefaultMinFrames = 1
    Field Value
    Type Description
    Int32

    DefaultTimeout

    Declaration
    public const float DefaultTimeout = 4F
    Field Value
    Type Description
    Single

    Properties

    IsNetcodeIntegrationTestRunning

    Declaration
    public static bool IsNetcodeIntegrationTestRunning { get; }
    Property Value
    Type Description
    Boolean

    NetworkManagerInstances

    Declaration
    public static List<NetworkManager> NetworkManagerInstances { get; }
    Property Value
    Type Description
    List<NetworkManager>

    Methods

    CleanUpHandlers()

    Call this to clean up the IntegrationTestSceneHandler and destroy the s_CoroutineRunner. Note: If deriving from NetcodeIntegrationTest or using Destroy() then you typically won't need to do this.

    Declaration
    public static void CleanUpHandlers()

    Create(Int32, out NetworkManager, out NetworkManager[], Int32, Boolean)

    Creates NetworkingManagers and configures them for use in a multi instance setting.

    Declaration
    public static bool Create(int clientCount, out NetworkManager server, out NetworkManager[] clients, int targetFrameRate = 60, bool serverFirst = true)
    Parameters
    Type Name Description
    Int32 clientCount

    The amount of clients

    NetworkManager server

    The server NetworkManager

    NetworkManager[] clients

    The clients NetworkManagers

    Int32 targetFrameRate

    The targetFrameRate of the Unity engine to use while the multi instance helper is running. Will be reset on shutdown.

    Boolean serverFirst

    This determines if the server or clients will be instantiated first (defaults to server first)

    Returns
    Type Description
    Boolean

    CreateNetworkObjectPrefab(String, NetworkManager, NetworkManager[])

    Declaration
    public static GameObject CreateNetworkObjectPrefab(string baseName, NetworkManager server, params NetworkManager[] clients)
    Parameters
    Type Name Description
    String baseName
    NetworkManager server
    NetworkManager[] clients
    Returns
    Type Description
    GameObject

    CreateNewClients(Int32, out NetworkManager[])

    Used to add a client to the already existing list of clients

    Declaration
    public static bool CreateNewClients(int clientCount, out NetworkManager[] clients)
    Parameters
    Type Name Description
    Int32 clientCount

    The amount of clients

    NetworkManager[] clients
    Returns
    Type Description
    Boolean

    CreateServer()

    Declaration
    public static NetworkManager CreateServer()
    Returns
    Type Description
    NetworkManager

    Destroy()

    Should always be invoked when finished with a single unit test (i.e. during TearDown)

    Declaration
    public static void Destroy()

    GetNetworkObjectByRepresentation(Func<NetworkObject, Boolean>, NetworkManager, NetcodeIntegrationTestHelpers.ResultWrapper<NetworkObject>, Boolean, Single)

    Gets a NetworkObject instance as it's represented by a certain peer.

    Declaration
    public static IEnumerator GetNetworkObjectByRepresentation(Func<NetworkObject, bool> predicate, NetworkManager representation, NetcodeIntegrationTestHelpers.ResultWrapper<NetworkObject> result, bool failIfNull = true, float timeout = 4F)
    Parameters
    Type Name Description
    Func<NetworkObject, Boolean> predicate

    The predicate used to filter for your target NetworkObject

    NetworkManager representation

    The representation to get the object from

    NetcodeIntegrationTestHelpers.ResultWrapper<NetworkObject> result

    The result

    Boolean failIfNull

    Whether or not to fail if no object is found and result is null

    Single timeout
    Returns
    Type Description
    IEnumerator

    GetNetworkObjectByRepresentation(UInt64, NetworkManager, NetcodeIntegrationTestHelpers.ResultWrapper<NetworkObject>, Boolean, Single)

    Gets a NetworkObject instance as it's represented by a certain peer.

    Declaration
    public static IEnumerator GetNetworkObjectByRepresentation(ulong networkObjectId, NetworkManager representation, NetcodeIntegrationTestHelpers.ResultWrapper<NetworkObject> result, bool failIfNull = true, float timeout = 4F)
    Parameters
    Type Name Description
    UInt64 networkObjectId

    The networkObjectId to get

    NetworkManager representation

    The representation to get the object from

    NetcodeIntegrationTestHelpers.ResultWrapper<NetworkObject> result

    The result

    Boolean failIfNull

    Whether or not to fail if no object is found and result is null

    Single timeout
    Returns
    Type Description
    IEnumerator

    GetNextGlobalIdHashValue()

    Declaration
    public static uint GetNextGlobalIdHashValue()
    Returns
    Type Description
    UInt32

    MakeNetworkObjectTestPrefab(NetworkObject, UInt32)

    Normally we would only allow player prefabs to be set to a prefab. Not runtime created objects. In order to prevent having a Resource folder full of a TON of prefabs that we have to maintain, MultiInstanceHelper has a helper function that lets you mark a runtime created object to be treated as a prefab by the Netcode. That's how we can get away with creating the player prefab at runtime without it being treated as a SceneObject or causing other conflicts with the Netcode.

    Declaration
    public static void MakeNetworkObjectTestPrefab(NetworkObject networkObject, uint globalObjectIdHash = 0U)
    Parameters
    Type Name Description
    NetworkObject networkObject

    The networkObject to be treated as Prefab

    UInt32 globalObjectIdHash

    The GlobalObjectId to force

    MarkAsSceneObjectRoot(GameObject, NetworkManager, NetworkManager[])

    Declaration
    public static void MarkAsSceneObjectRoot(GameObject networkObjectRoot, NetworkManager server, NetworkManager[] clients)
    Parameters
    Type Name Description
    GameObject networkObjectRoot
    NetworkManager server
    NetworkManager[] clients

    RegisterHandlers(NetworkManager, Boolean)

    Call this to register scene validation and the IntegrationTestSceneHandler Note: If deriving from NetcodeIntegrationTest or using Destroy() then you typically won't need to call this.

    Declaration
    public static void RegisterHandlers(NetworkManager networkManager, bool serverSideSceneManager = false)
    Parameters
    Type Name Description
    NetworkManager networkManager
    Boolean serverSideSceneManager

    RegisterNetcodeIntegrationTest(Boolean)

    Declaration
    public static void RegisterNetcodeIntegrationTest(bool registered)
    Parameters
    Type Name Description
    Boolean registered

    Start(Boolean, NetworkManager, NetworkManager[], NetcodeIntegrationTestHelpers.BeforeClientStartCallback)

    Starts NetworkManager instances created by the Create method.

    Declaration
    public static bool Start(bool host, NetworkManager server, NetworkManager[] clients, NetcodeIntegrationTestHelpers.BeforeClientStartCallback callback = null)
    Parameters
    Type Name Description
    Boolean host

    Whether or not to create a Host instead of Server

    NetworkManager server

    The Server NetworkManager

    NetworkManager[] clients

    The Clients NetworkManager

    NetcodeIntegrationTestHelpers.BeforeClientStartCallback callback

    called immediately after server is started and before client(s) are started

    Returns
    Type Description
    Boolean

    StartOneClient(NetworkManager)

    Starts one single client and makes sure to register the required hooks and handlers

    Declaration
    public static void StartOneClient(NetworkManager clientToStart)
    Parameters
    Type Name Description
    NetworkManager clientToStart

    StopOneClient(NetworkManager, Boolean)

    Stops one single client and makes sure to cleanup any static variables in this helper

    Declaration
    public static void StopOneClient(NetworkManager clientToStop, bool destroy = true)
    Parameters
    Type Name Description
    NetworkManager clientToStop
    Boolean destroy

    WaitForClientConnected(NetworkManager, NetcodeIntegrationTestHelpers.ResultWrapper<Boolean>, Single)

    Waits on the client side to be connected.

    Declaration
    public static IEnumerator WaitForClientConnected(NetworkManager client, NetcodeIntegrationTestHelpers.ResultWrapper<bool> result = null, float timeout = 4F)
    Parameters
    Type Name Description
    NetworkManager client

    The client

    NetcodeIntegrationTestHelpers.ResultWrapper<Boolean> result

    The result. If null, it will automatically assert

    Single timeout
    Returns
    Type Description
    IEnumerator

    WaitForClientConnectedToServer(NetworkManager, NetcodeIntegrationTestHelpers.ResultWrapper<Boolean>, Single)

    Waits on the server side for 1 client to be connected

    Declaration
    public static IEnumerator WaitForClientConnectedToServer(NetworkManager server, NetcodeIntegrationTestHelpers.ResultWrapper<bool> result = null, float timeout = 4F)
    Parameters
    Type Name Description
    NetworkManager server

    The server

    NetcodeIntegrationTestHelpers.ResultWrapper<Boolean> result

    The result. If null, it will automatically assert

    Single timeout
    Returns
    Type Description
    IEnumerator

    WaitForClientsConnected(NetworkManager[], NetcodeIntegrationTestHelpers.ResultWrapper<Boolean>, Single)

    Declaration
    public static IEnumerator WaitForClientsConnected(NetworkManager[] clients, NetcodeIntegrationTestHelpers.ResultWrapper<bool> result = null, float timeout = 4F)
    Parameters
    Type Name Description
    NetworkManager[] clients
    NetcodeIntegrationTestHelpers.ResultWrapper<Boolean> result
    Single timeout
    Returns
    Type Description
    IEnumerator

    WaitForClientsConnectedToServer(NetworkManager, Int32, NetcodeIntegrationTestHelpers.ResultWrapper<Boolean>, Single)

    Waits on the server side for 1 client to be connected

    Declaration
    public static IEnumerator WaitForClientsConnectedToServer(NetworkManager server, int clientCount = 1, NetcodeIntegrationTestHelpers.ResultWrapper<bool> result = null, float timeout = 4F)
    Parameters
    Type Name Description
    NetworkManager server

    The server

    Int32 clientCount
    NetcodeIntegrationTestHelpers.ResultWrapper<Boolean> result

    The result. If null, it will automatically assert

    Single timeout
    Returns
    Type Description
    IEnumerator

    WaitForCondition(Func<Boolean>, NetcodeIntegrationTestHelpers.ResultWrapper<Boolean>, Single, Int32)

    Waits for a predicate condition to be met

    Declaration
    public static IEnumerator WaitForCondition(Func<bool> predicate, NetcodeIntegrationTestHelpers.ResultWrapper<bool> result = null, float timeout = 4F, int minFrames = 1)
    Parameters
    Type Name Description
    Func<Boolean> predicate

    The predicate to wait for

    NetcodeIntegrationTestHelpers.ResultWrapper<Boolean> result

    The result. If null, it will fail if the predicate is not met

    Single timeout
    Int32 minFrames

    The min frames to wait for

    Returns
    Type Description
    IEnumerator
    Back to top Copyright © 2023 Unity Technologies — Terms of use
    Generated by DocFX
    on 26 October 2023