DOTSNET
  • Documentation
  • Overview
    • Installation
    • Recommended Reading
    • Platforms
    • Changelog
  • Examples
    • Benchmark
    • Chat
    • Pong
    • Physics
  • User Manual
    • Migrating from Mirror
    • Authoring
    • Server & Client Worlds
    • Selective System Authoring
    • Dependency Injection
    • NetworkMessage
    • NetworkServerSystem
    • NetworkClientSystem
    • NetworkIdentity
    • NetworkComponent
    • PrefabSystem
    • NetworkReader/Writer
    • Bitpacking
    • Authentication
    • Interest Management
    • Transports
    • Networking & Burst
    • Networking & Jobs
    • Compression
    • Utilities & Extensions
    • Unity.Physics Support
    • Hybrid Renderer V2 / URP
    • Benchmarks
Powered by GitBook
On this page
  1. User Manual

NetworkClientSystem

PreviousNetworkServerSystemNextNetworkIdentity

Last updated 3 years ago

NetworkClientSystem is the main client class, found in ClientWorld.

NetworkClientSystemAuthoring can be used to interact with it from the Inspector. In the example scene, the NetworkClient scene object has the authoring component:

NetworkClientSystem API

Property:

Description:

state

Current client state (disconnected/connecting/connected).

disconnectedFreezesScene

Convenience feature that decides what to do after the client disconnects. By default, all NetworkEntities will be destroyed and cleaned up immediately.

Enable this flag to freeze them in the scene instead, which is what some MMOs do because it looks cool.

The NetworkEntities will automatically be cleaned up in the next Connect() call again.

spawned

All spawned Entities by netId that are around the player. Unlike the server, those aren’t all entities that were spawned in the world. Only the player’s observers.

Function:

Description:

Connect(address)

Connect to a server listening on the specified address. This is not blocking, it will simply start the connect process, set the state to CONNECTING and then to CONNECTED a bit later.

Disconnect()

Disconnect from the server. This happens immediately and the state is set to DISCONNECTED.

Send(message, channel)

Send a NetworkMessage to the server.

Some transports support different channels.

If in doubt, leave the channel at default = Reliable.

OnConnected()

Virtual function for classes that inherit from NetworkClientSystem.

OnDisconnected()

Virtual function for classes that inherit from NetworkClientSystem.

RegisterHandler<T>(handler)

Register a handler for an incoming message. Inheriting from NetworkClientMessageSystem registers it automatically.

NOTE: custom allocator for the new NetworkMessage<T> can be passed as third parameter in case a system wants to reuse large messages like WorldStateMessage instead of allocating each time.

UnregisterHandler<T>

Unregister handler for the NetworkMessage type.