docs.unity3d.com
    Show / Hide Table of Contents

    Class NetcodeIntegrationTest

    The default Netcode for GameObjects integration test helper class

    Inheritance
    Object
    NetcodeIntegrationTest
    AddNetworkPrefabTest
    ConnectionApprovalTimeoutTests
    DeferredMessagingTest
    DisconnectReasonTests
    HiddenVariableTests
    IntegrationTestExtended
    IntegrationTestPlayers
    IntegrationTestSpawning
    IntegrationTestUpdated
    InvalidConnectionEventsTest
    NamedMessageTests
    NetworkBehaviourGenericTests
    NetworkBehaviourReferenceIntegrationTests
    NetworkBehaviourUpdaterTests
    NetworkListChangedTests
    NetworkObjectDestroyTests
    NetworkObjectDontDestroyWithOwnerTests
    NetworkObjectNetworkClientOwnedObjectsTests
    NetworkObjectOnSpawnTests
    NetworkObjectOwnershipTests
    NetworkObjectSpawnManyObjectsTests
    NetworkObjectSynchronizationTests
    NetworkShowHideTests
    NetworkSpawnManagerTests
    NetworkTransformTests
    NetworkVarBufferCopyTest
    NetworkVariablePermissionTests
    NetworkVariableTests
    NetworkVariableUserSerializableTypesTests
    NetworkVisibilityTests
    OwnerModifiedTests
    OwnerPermissionHideTests
    PlayerObjectTests
    RpcManyClientsTests
    RpcTests
    StopStartRuntimeTests
    TimeIntegrationTest
    TransformInterpolationTests
    UnnamedMessageTests
    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 abstract class NetcodeIntegrationTest

    Constructors

    NetcodeIntegrationTest()

    Default constructor

    Declaration
    public NetcodeIntegrationTest()

    NetcodeIntegrationTest(NetcodeIntegrationTest.HostOrServer)

    Optional Host or Server integration tests Constructor that allows you To break tests up as a host and a server. Example: Decorate your child derived class with TestFixture and then create a constructor at the child level. Don't forget to set your constructor public, else Unity will give you a hard to decipher error [TestFixture(HostOrServer.Host)] [TestFixture(HostOrServer.Server)] public class MyChildClass : NetcodeIntegrationTest { public MyChildClass(HostOrServer hostOrServer) : base(hostOrServer) { } }

    Declaration
    public NetcodeIntegrationTest(NetcodeIntegrationTest.HostOrServer hostOrServer)
    Parameters
    Type Name Description
    NetcodeIntegrationTest.HostOrServer hostOrServer

    Fields

    k_DefaultTickRate

    Declaration
    protected const uint k_DefaultTickRate = 30U
    Field Value
    Type Description
    UInt32

    m_ClientNetworkManagers

    Declaration
    protected NetworkManager[] m_ClientNetworkManagers
    Field Value
    Type Description
    NetworkManager[]

    m_CreateServerFirst

    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.

    Declaration
    protected bool m_CreateServerFirst
    Field Value
    Type Description
    Boolean

    m_PlayerNetworkObjects

    Contains each client relative set of player NetworkObject instances [Client Relative set of player instances][The player instance ClientId][The player instance's NetworkObject] Example: To get the player instance with a ClientId of 3 that was instantiated (relative) on the player instance with a ClientId of 2 m_PlayerNetworkObjects[2][3]

    Declaration
    protected Dictionary<ulong, Dictionary<ulong, NetworkObject>> m_PlayerNetworkObjects
    Field Value
    Type Description
    Dictionary<UInt64, Dictionary<UInt64, NetworkObject>>

    m_PlayerPrefab

    Declaration
    protected GameObject m_PlayerPrefab
    Field Value
    Type Description
    GameObject

    m_ServerNetworkManager

    Declaration
    protected NetworkManager m_ServerNetworkManager
    Field Value
    Type Description
    NetworkManager

    m_TargetFrameRate

    Declaration
    protected int m_TargetFrameRate
    Field Value
    Type Description
    Int32

    m_UseHost

    Declaration
    protected bool m_UseHost
    Field Value
    Type Description
    Boolean

    NetcodeLogAssert

    Declaration
    public NetcodeLogAssert NetcodeLogAssert
    Field Value
    Type Description
    NetcodeLogAssert

    s_DefaultWaitForTick

    Declaration
    protected static WaitForSecondsRealtime s_DefaultWaitForTick
    Field Value
    Type Description
    WaitForSecondsRealtime

    s_GlobalNetworkObjects

    Registered list of all NetworkObjects spawned. Format is as follows: [ClientId-side where this NetworkObject instance resides][NetworkObjectId][NetworkObject] Where finding the NetworkObject with a NetworkObjectId of 10 on ClientId of 2 would be: s_GlobalNetworkObjects[2][10] To find the client or server player objects please see: m_PlayerNetworkObjects

    Declaration
    protected static Dictionary<ulong, Dictionary<ulong, NetworkObject>> s_GlobalNetworkObjects
    Field Value
    Type Description
    Dictionary<UInt64, Dictionary<UInt64, NetworkObject>>

    s_GlobalTimeoutHelper

    Declaration
    protected static TimeoutHelper s_GlobalTimeoutHelper
    Field Value
    Type Description
    TimeoutHelper

    Properties

    LogAllMessages

    Declaration
    protected virtual bool LogAllMessages { get; }
    Property Value
    Type Description
    Boolean

    m_BypassConnectionTimeout

    When set to true, this will bypass the entire wait for clients to connect process.

    Declaration
    protected bool m_BypassConnectionTimeout { get; set; }
    Property Value
    Type Description
    Boolean
    Remarks

    CAUTION: Setting this to true will bypass other helper identification related code, so this should only be used for connection failure oriented testing

    m_EnableVerboseDebug

    Declaration
    protected bool m_EnableVerboseDebug { get; set; }
    Property Value
    Type Description
    Boolean

    NumberOfClients

    Declaration
    protected abstract int NumberOfClients { get; }
    Property Value
    Type Description
    Int32

    TotalClients

    Declaration
    protected int TotalClients { get; }
    Property Value
    Type Description
    Int32

    Methods

    AssertOnTimeout(String, TimeoutHelper)

    Just a helper function to avoid having to write the entire assert just to check if you timed out.

    Declaration
    protected void AssertOnTimeout(string timeOutErrorMessage, TimeoutHelper assignedTimeoutHelper = null)
    Parameters
    Type Name Description
    String timeOutErrorMessage
    TimeoutHelper assignedTimeoutHelper

    CanClientsLoad()

    Override this method to control when clients can fake-load a scene.

    Declaration
    protected virtual bool CanClientsLoad()
    Returns
    Type Description
    Boolean

    CanClientsUnload()

    Override this method to control when clients can fake-unload a scene.

    Declaration
    protected virtual bool CanClientsUnload()
    Returns
    Type Description
    Boolean

    CanDestroyNetworkObject(NetworkObject)

    Override this to filter out the NetworkObjects that you want to allow to persist between integration tests. DestroySceneNetworkObjects() ShutdownAndCleanUp()

    Declaration
    protected virtual bool CanDestroyNetworkObject(NetworkObject networkObject)
    Parameters
    Type Name Description
    NetworkObject networkObject

    the network object in question to be destroyed

    Returns
    Type Description
    Boolean

    CanStartServerAndClients()

    Override this method and return false in order to be able to manually control when the server and clients are started.

    Declaration
    protected virtual bool CanStartServerAndClients()
    Returns
    Type Description
    Boolean

    ClientNetworkManagerPostStartInit()

    Declaration
    protected void ClientNetworkManagerPostStartInit()

    CreateAndStartNewClient()

    This will create, start, and connect a new client while in the middle of an integration test.

    Declaration
    protected IEnumerator CreateAndStartNewClient()
    Returns
    Type Description
    IEnumerator

    CreateNetworkObjectPrefab(String)

    Creates a basic NetworkObject test prefab, assigns it to a new NetworkPrefab entry, and then adds it to the server and client(s) NetworkManagers' NetworkConfig.NetworkPrefab lists.

    Declaration
    protected GameObject CreateNetworkObjectPrefab(string baseName)
    Parameters
    Type Name Description
    String baseName

    the basic name to be used for each instance

    Returns
    Type Description
    GameObject

    NetworkObject of the GameObject assigned to the new NetworkPrefab entry

    CreateServerAndClients()

    Will create NumberOfClients number of clients. To create a specific number of clients CreateServerAndClients(Int32)

    Declaration
    protected void CreateServerAndClients()

    CreateServerAndClients(Int32)

    Creates the server and clients

    Declaration
    protected void CreateServerAndClients(int numberOfClients)
    Parameters
    Type Name Description
    Int32 numberOfClients

    DeregisterNetworkObject(UInt64, UInt64)

    Declaration
    public static void DeregisterNetworkObject(ulong localClientId, ulong networkObjectId)
    Parameters
    Type Name Description
    UInt64 localClientId
    UInt64 networkObjectId

    DeregisterNetworkObject(NetworkObject)

    Declaration
    public static void DeregisterNetworkObject(NetworkObject networkObject)
    Parameters
    Type Name Description
    NetworkObject networkObject

    DeRegisterSceneManagerHandler()

    De-Registers from the CanClientsLoad and CanClientsUnload events of the ClientSceneHandler (default is IntegrationTestSceneHandler).

    Declaration
    protected void DeRegisterSceneManagerHandler()

    DestroySceneNetworkObjects()

    Destroys all NetworkObjects at the end of a test cycle.

    Declaration
    protected void DestroySceneNetworkObjects()

    EnableMessageLogging()

    For debugging purposes, this will turn on verbose logging of all messages and batches sent and received

    Declaration
    protected void EnableMessageLogging()

    OnCanSceneCleanUpUnload(Scene)

    Declaration
    protected bool OnCanSceneCleanUpUnload(Scene scene)
    Parameters
    Type Name Description
    Scene scene
    Returns
    Type Description
    Boolean

    OnCreatePlayerPrefab()

    Override this to add components or adjustments to the default player prefab m_PlayerPrefab

    Declaration
    protected virtual void OnCreatePlayerPrefab()

    OneTimeSetup()

    Declaration
    public void OneTimeSetup()

    OneTimeTearDown()

    Declaration
    public void OneTimeTearDown()

    OnNewClientCreated(NetworkManager)

    CreateAndStartNewClient Only Invoked when the newly created client has been created

    Declaration
    protected virtual void OnNewClientCreated(NetworkManager networkManager)
    Parameters
    Type Name Description
    NetworkManager networkManager

    OnNewClientStarted(NetworkManager)

    CreateAndStartNewClient Only Invoked when the newly created client has been created and started

    Declaration
    protected virtual void OnNewClientStarted(NetworkManager networkManager)
    Parameters
    Type Name Description
    NetworkManager networkManager

    OnNewClientStartedAndConnected(NetworkManager)

    CreateAndStartNewClient Only Invoked when the newly created client has been created, started, and connected to the server-host.

    Declaration
    protected virtual void OnNewClientStartedAndConnected(NetworkManager networkManager)
    Parameters
    Type Name Description
    NetworkManager networkManager

    OnOneTimeSetup()

    Declaration
    protected virtual void OnOneTimeSetup()

    OnOneTimeTearDown()

    Override this method to do handle cleaning up once the test(s) within the child derived class have completed Note: For AllTests mode this is called before ShutdownAndCleanUp.

    Declaration
    protected virtual void OnOneTimeTearDown()

    OnPlayerPrefabGameObjectCreated()

    Invoked immediately after the player prefab GameObject is created prior to adding a NetworkObject component

    Declaration
    protected virtual void OnPlayerPrefabGameObjectCreated()

    OnServerAndClientsConnected()

    Invoked after the server and clients have started and verified their connections with each other.

    Declaration
    protected virtual IEnumerator OnServerAndClientsConnected()
    Returns
    Type Description
    IEnumerator

    OnServerAndClientsCreated()

    This is invoked before the server and client(s) are started. Override this method if you want to make any adjustments to their NetworkManager instances.

    Declaration
    protected virtual void OnServerAndClientsCreated()

    OnSetIntegrationTestMode()

    The very first thing invoked during the OneTimeSetup() that determines how this integration test handles NetworkManager instantiation and destruction. NetcodeIntegrationTest.NetworkManagerInstatiationMode Override this method to change the default mode: AllTests

    Declaration
    protected virtual NetcodeIntegrationTest.NetworkManagerInstatiationMode OnSetIntegrationTestMode()
    Returns
    Type Description
    NetcodeIntegrationTest.NetworkManagerInstatiationMode

    OnSetup()

    Called before creating and starting the server and clients Note: For AllTests and PerTest mode integration tests. For those two modes, if you want to have access to the server or client NetworkManagers then override OnServerAndClientsCreated(). m_ServerNetworkManager and m_ClientNetworkManagers

    Declaration
    protected virtual IEnumerator OnSetup()
    Returns
    Type Description
    IEnumerator

    OnSetVerboseDebug()

    Override this and return true if you need to troubleshoot a hard to track bug within an integration test.

    Declaration
    protected virtual bool OnSetVerboseDebug()
    Returns
    Type Description
    Boolean

    OnStartedServerAndClients()

    Invoked after the server and clients have started. Note: No connection verification has been done at this point

    Declaration
    protected virtual IEnumerator OnStartedServerAndClients()
    Returns
    Type Description
    IEnumerator

    OnTearDown()

    Note: For PerTest mode this is called before ShutdownAndCleanUp.

    Declaration
    protected virtual IEnumerator OnTearDown()
    Returns
    Type Description
    IEnumerator

    RegisterNetworkObject(NetworkObject)

    Declaration
    public static void RegisterNetworkObject(NetworkObject networkObject)
    Parameters
    Type Name Description
    NetworkObject networkObject

    RegisterSceneManagerHandler()

    Registers the CanClientsLoad and CanClientsUnload events of the ClientSceneHandler. The default is: Unity.Netcode.TestHelpers.Runtime.IntegrationTestSceneHandler.

    Declaration
    protected void RegisterSceneManagerHandler()

    SetUp()

    Declaration
    public IEnumerator SetUp()
    Returns
    Type Description
    IEnumerator

    ShutdownAndCleanUp()

    This shuts down all NetworkManager instances registered via the NetcodeIntegrationTestHelpers class and cleans up the test runner scene of any left over NetworkObjects. DestroySceneNetworkObjects()

    Declaration
    protected void ShutdownAndCleanUp()

    SpawnObject(GameObject, NetworkManager, Boolean)

    Overloaded method Unity.Netcode.TestHelpers.Runtime.NetcodeIntegrationTest.SpawnObject(Unity.Netcode.NetworkObject,Unity.Netcode.NetworkManager,System.Boolean)

    Declaration
    protected GameObject SpawnObject(GameObject prefabGameObject, NetworkManager owner, bool destroyWithScene = false)
    Parameters
    Type Name Description
    GameObject prefabGameObject
    NetworkManager owner
    Boolean destroyWithScene
    Returns
    Type Description
    GameObject

    SpawnObjects(GameObject, NetworkManager, Int32, Boolean)

    Overloaded method Unity.Netcode.TestHelpers.Runtime.NetcodeIntegrationTest.SpawnObjects(Unity.Netcode.NetworkObject,Unity.Netcode.NetworkManager,System.Int32,System.Boolean)

    Declaration
    protected List<GameObject> SpawnObjects(GameObject prefabGameObject, NetworkManager owner, int count, bool destroyWithScene = false)
    Parameters
    Type Name Description
    GameObject prefabGameObject
    NetworkManager owner
    Int32 count
    Boolean destroyWithScene
    Returns
    Type Description
    List<GameObject>

    StartServerAndClients()

    This starts the server and clients as long as CanStartServerAndClients() returns true.

    Declaration
    protected IEnumerator StartServerAndClients()
    Returns
    Type Description
    IEnumerator

    StopOneClient(NetworkManager, Boolean)

    This will stop a client while in the middle of an integration test

    Declaration
    protected IEnumerator StopOneClient(NetworkManager networkManager, bool destroy = false)
    Parameters
    Type Name Description
    NetworkManager networkManager
    Boolean destroy
    Returns
    Type Description
    IEnumerator

    TearDown()

    Declaration
    public IEnumerator TearDown()
    Returns
    Type Description
    IEnumerator

    VerboseDebug(String)

    Used to display the various integration test stages and can be used to log verbose information for troubleshooting an integration test.

    Declaration
    protected void VerboseDebug(string msg)
    Parameters
    Type Name Description
    String msg

    WaitForClientsConnectedOrTimeOut()

    Overloaded method that just passes in all clients to WaitForClientsConnectedOrTimeOut(NetworkManager[])

    Declaration
    protected IEnumerator WaitForClientsConnectedOrTimeOut()
    Returns
    Type Description
    IEnumerator

    WaitForClientsConnectedOrTimeOut(NetworkManager[])

    Validates that all remote clients (i.e. non-server) detect they are connected to the server and that the server reflects the appropriate number of clients have connected or it will time out.

    Declaration
    protected IEnumerator WaitForClientsConnectedOrTimeOut(NetworkManager[] clientsToCheck)
    Parameters
    Type Name Description
    NetworkManager[] clientsToCheck

    An array of clients to be checked

    Returns
    Type Description
    IEnumerator

    WaitForConditionOrTimeOut(Func<Boolean>, TimeoutHelper)

    Waits for the function condition to return true or it will time out. This will operate at the current m_ServerNetworkManager.NetworkConfig.TickRate and allow for a unique TimeoutHelper handler (if none then it uses the default) Notes: This provides more stability when running integration tests that could be impacted by: -how the integration test is being executed (i.e. in editor or in a stand alone build) -potential platform performance issues (i.e. VM is throttled or maxed) Note: For more complex tests, ConditionalPredicateBase and the overloaded version of this method

    Declaration
    public static IEnumerator WaitForConditionOrTimeOut(Func<bool> checkForCondition, TimeoutHelper timeOutHelper = null)
    Parameters
    Type Name Description
    Func<Boolean> checkForCondition
    TimeoutHelper timeOutHelper
    Returns
    Type Description
    IEnumerator

    WaitForConditionOrTimeOut(IConditionalPredicate, TimeoutHelper)

    This version accepts an IConditionalPredicate implementation to provide more flexibility for checking complex conditional cases.

    Declaration
    public static IEnumerator WaitForConditionOrTimeOut(IConditionalPredicate conditionalPredicate, TimeoutHelper timeOutHelper = null)
    Parameters
    Type Name Description
    IConditionalPredicate conditionalPredicate
    TimeoutHelper timeOutHelper
    Returns
    Type Description
    IEnumerator

    WaitForTicks(NetworkManager, Int32)

    Yields until specified amount of network ticks and the expected number of frames has been passed.

    Declaration
    protected IEnumerator WaitForTicks(NetworkManager networkManager, int count)
    Parameters
    Type Name Description
    NetworkManager networkManager
    Int32 count
    Returns
    Type Description
    IEnumerator
    Back to top Copyright © 2023 Unity Technologies — Terms of use
    Generated by DocFX
    on 26 October 2023