LogoLogo
  • SWNetwork SDK Overview
  • Installation
    • Custom Unity Package
  • Tutorials
    • Third-Person Shooter
      • Starter Project Introduction
      • Install SWNetwork
      • Setting up the NetworkClient
      • Sync Player Transform
      • Setting up the Scene Spawner
      • Test and Play
      • Remote Events
      • SyncProperties
      • Player Respawn
      • Updating Room States
      • Winning the Game
    • Basic Lobby
      • Lobby-start
      • Installing SWNetwork SDK and configuring NetworkClient
      • Registering Player
      • Room CRUD
      • Managing Teams
      • Chat
  • SDK
    • Network Client
      • Check-in
      • Game Servers
      • Network Status Event (beta)
      • Classes
        • NetworkClient Class
      • Methods
        • CheckIn() Method
        • ConnectToRoom(Action<bool>) Method
        • DisconnectFromRoom () Method
        • FindSpawner(ushort) Method
    • Game Play
      • Network ID
      • Realtime Agent
      • Remote Event
      • Sync Property
        • Restore Sync Properties
        • Conflict Resolution
      • SceneSpawner
      • RoomPropertyAgent
      • RoomRemoteEventAgent
    • Lobby
      • Register Player
      • Message Player
      • Create Room
      • Change Room Settings
      • Get Rooms
      • Filter Rooms
      • Join Room
      • Message Room
      • Get Players in Room
      • Get Room Custom Data
      • Change Room Custom Data
      • Kick Players
      • Start Room
      • Leave Room
      • Lobby Room Events
        • OnLobbyConnectedEvent
        • OnPlayerMessageEvent
        • OnRoomCustomDataChangeEvent
        • OnNewPlayerJoinRoomEvent
        • OnPlayerLeaveRoomEvent
        • OnNewRoomOwnerEvent
        • OnRoomStartingEvent
        • OnRoomReadyEvent
        • OnFailedToStartRoomEvent
        • OnKickedEvent
        • OnRoomMessageEvent
      • Classes
        • SWLobby Class
        • SWPlayer Class
        • SWRoom Class
        • SWRegisterReply Class
        • SWGetRoomReply Class
        • SWJoinRoomReply Class
        • SWGetRoomCustomDataReply Class
        • SWGetPlayersReply Class
        • SWLobbyIndexData Class
        • SWLobbyFilterData Class
        • SWGetRoomFilterReply Class
        • SWLobbyError Class
        • SWMessagePlayerEventData Class
        • SWMessageRoomEventData Class
        • SWRoomCustomDataChangeEventData Class
        • SWJoinRoomEventData Class
        • SWLeaveRoomEventData Class
        • SWRoomChangeOwnerEventData Class
        • SWStartRoomEventData Class
        • SWRoomReadyEventData Class
        • SWFailedToStartRoomEventData Class
      • Methods
        • Register(Action<bool, SWRegisterReply, SWLobbyError>) Method
        • MessagePlayer(string, string, Action<bool, SWLobbyError>) Method
        • CreateRoom(bool, int, Action<bool, string, SWLobbyError>) Method
        • ChangeRoomSettings(int, int, Action<bool, SWLobbyError>) Method
        • GetRooms(int, int, Action<bool, SWGetRoomReply, SWLobbyError>) Method
        • FilterRoom(SWLobbyFilterData, byte, Action<bool, SWGetRoomFilterReply, SWLobbyError>) Method
        • JoinRoom(string, Action<bool, SWJoinRoomReply, SWLobbyError>) Method
        • JoinRoomRandomly(Action<bool, SWJoinRoomReply, SWLobbyError>) Method
        • JoinOrCreateRoom(bool, int, int, Action<bool, SWJoinRoomReply, SWLobbyError>) Method
        • MessageRoom(string, Action<bool, SWLobbyError>) Method
        • GetRoomCustomData(Action<bool, SWGetRoomCustomDataReply, SWLobbyError>) Method
        • GetPlayersInRoom(Action<bool, SWGetPlayersReply, SWLobbyError>) Method
        • ChangeRoomCustomData(string, Action<bool, SWLobbyError>) Method
        • StartRoom(Action<bool, SWLobbyError>) Method
        • LeaveRoom(Action<bool, SWLobbyError>) Method
  • Open Source Software Used
    • Credits
Powered by GitBook
On this page
  • NetworkID Class
  • Examples

Was this helpful?

  1. SDK
  2. Game Play

Network ID

Used to Identify a GameObject in a networked game.

PreviousGame PlayNextRealtime Agent

Last updated 5 years ago

Was this helpful?

Name

Function

ID

Automatically assign at run time.

OwnerRemotePlayerId

The owner's full playerId.

OwnerCustomPlayerId

The owner's custom playerId.

Type

Player: Player controlled GameObject

Non-Player: Non-player controlled GameObject

SendRealtimeData

Indicates whether the Networked GameObject sends Realtime data to the game server. Only controls the behaviour of non-player networked GameObjects

DynamicallySpawned

Disable this for non-player Networked GameObjects that are not spawned/destroyed by the SceneSpawner.

FixedNetworkObjectID

The Fixed NetworkObjectID of the non-player Networked GameObject that are not spawned/destroyed by the SceneSpawner.

A valid FixedNetworkObjectIDs should be between 1-4999

Filterable

Indicates whether the GameObject can be filtered by the realtime filter. Only controls the behaviour of player networked GameObjects

Visible Size

Size of the bounding box of the GameObject

NetworkID Class

Find out if local player is the owner of a Networked GameObject

public bool IsMine;

Removes the networked GameObject across the network. The optional parameter specifies the amount of delay in seconds before destroying the networked GameObject.

public void Destroy(float delay = 0.0f);

FAQ

Question: What would be the best way to restore a player status (position, health, etc.) after he closes the game and comes back a moment later? The SceneSpawner would just spawn a new player GameObject, but I'd like to restore its status to when he disconnected

Background: Every Networked Object must have a NetworkID component, and the SDK assigns a unique id to each NetworkID component.

The id has a range from 1 to 65535.

1-25000 is reserved for player-owned objects. each player can have up to 100 networked objects so id of 100-199 is owned by player 1 in the game, 200-299 is owned by player 2 in the game...

When players connect to the room game server, the game server will assign roomPlayerIDs to them, and roomPlayerID 1 will be assigned to the first player connects to the room. roomPlayerID 2 will be assigned to the second player connects to the room...

Examples

Only the GameObjects that the local player owns should receive input updates.

In this example, networkId.IsMine is called to find out if the local player has the authority to move the GameObject.

using UnityEngine;
using SWNetwork;

public class PlayerMovement : MonoBehaviour
{
    public float moveSpeed = 6.0F;
    
    CharacterController characterController;
    NetworkID networkId;

    void Start()
    {
        networkId = GetComponent<NetworkID>();
        characterController = GetComponent<CharacterController>();
    }

    void Update()
    {
        if (networkId.IsMine)
        {
            float speedX = Input.GetAxis("Horizontal") * moveSpeed;
            float speedZ = Input.GetAxis("Vertical") * moveSpeed;
            
            Vector3 movement = new Vector3(speedX, verticalVelocity, speedZ);
            characterController.Move(movement * Time.deltaTime);
        }
    }
}

Answer: If players leave temporarily and reconnect back to the rooms, you probably want to use a longer to create rooms. So players don't get removed from rooms too quickly.

If the first player went offline and reconnect back to the room game server before the room is over, the room game server still remembers the player's roomPlayerID(which is 1 in this case). so the player will gain ownership of the GameObjects with ID in the 100-199 range. If the first player went offline for too long and got kicked by the room keeper, the player's roomPlayerID will be recycled and appended to the end of the available roomPlayerID queue. So if the player joins the same room again, a new roomPlayerID will be assigned. Say the new roomPlayerID is 3, the player will create new sets of GameObjects and own GameObjects with ID in the 300-399 range.

playerTimeToLive
playerTimeToLive