docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class DirectNetworkOptions

    Represents configuration options for direct network connections.

    Inheritance
    object
    DirectNetworkOptions
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Unity.Services.Multiplayer
    Assembly: Unity.Services.Multiplayer.dll
    Syntax
    public class DirectNetworkOptions
    Remarks

    To listen on all interfaces, use AnyIpv4 or AnyIpv6 as the ListenIp and specify the external/public IP address that clients should use as the PublishIp.

    Using direct networking in client-hosted games reveals the IP address of players to the host. For client-hosted games, using Relay or Distributed Authority is recommended to handle NAT, firewalls and protect player privacy.

    If a non-zero value is used, the Port number applies to both listen and publish addresses.

    When using Netcode for Entities, the default Multiplayer Services Network handler requires that your Client and Server Worlds are created before you create or join a session. Using the default ClientServerBootstrap, automatically creates the client and server worlds at startup when the Netcode for Entities package is first added to your project. For more advanced use cases, use WithNetworkHandler<T>(T, INetworkHandler) to disable the default integration with Netcode for Entities.

    Constructors

    DirectNetworkOptions()

    Initializes a new instance of the DirectNetworkOptions class with default values (port 0, IPv4 loopback addresses).

    Declaration
    public DirectNetworkOptions()
    Remarks

    This constructor is incompatible with Netcode for GameObjects 1.x as providing a specific a port is required.

    DirectNetworkOptions(ushort)

    Initializes a new instance of the DirectNetworkOptions class with the specified port and default IPv4 loopback addresses for both listening and publishing.

    Declaration
    public DirectNetworkOptions(ushort port)
    Parameters
    Type Name Description
    ushort port

    The port number to use for the connection.

    DirectNetworkOptions(ListenIPAddress, PublishIPAddress, ushort)

    Initializes a new instance of the DirectNetworkOptions class with the specified network configuration.

    Declaration
    public DirectNetworkOptions(ListenIPAddress listenIp, PublishIPAddress publishIp, ushort port)
    Parameters
    Type Name Description
    ListenIPAddress listenIp

    The IP address to listen on for incoming connections.

    PublishIPAddress publishIp

    The IP address to publish for other clients to connect to.

    ushort port

    The port number to use for the connection.

    Properties

    ListenIp

    Gets the IP address to listen on for incoming connections.

    Declaration
    public ListenIPAddress ListenIp { get; }
    Property Value
    Type Description
    ListenIPAddress

    Port

    Gets the port number for the network connection.

    Declaration
    public ushort Port { get; }
    Property Value
    Type Description
    ushort

    PublishIp

    Gets the IP address to publish for other clients to connect to.

    Declaration
    public PublishIPAddress PublishIp { get; }
    Property Value
    Type Description
    PublishIPAddress
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)