Fish-Net: Networking Evolved
  • Introduction
    • Getting Started
    • Showcase
      • Upcoming Releases
    • Legal Restrictions
    • Pro, Projects, and Support
    • Business Support
    • Branding
  • Manual
    • General
      • Unity Compatibility
      • Changelog
        • Development Road Map
        • Major Version Update Solutions
      • Development
      • Performance
        • Benchmark Setup
        • Fish-Networking Vs Mirror
      • Terminology
        • Miscellaneous
        • Communicating
        • Server, Client, Host
      • Transports
      • Add-ons
        • Edgegap and other Hosting
        • Fish-Network-Discovery
      • Feature Comparison
      • Upgrading To Fish-Networking
    • Guides
      • Frequently Asked Questions (FAQ)
      • Creating Bug Reports
        • Report Example
      • Technical Limitations
      • Third-Party
      • Getting Started
        • Commonly Used Guides
        • Ownership - Moving Soon
        • Step-by-Step
          • Getting Connected
          • Preparing Your Player
      • Components
        • Managers
          • NetworkManager
          • TimeManager
          • PredictionManager
          • ServerManager
          • ClientManager
          • SceneManager
          • TransportManager
            • IntermediateLayer
          • StatisticsManager
          • ObserverManager
            • HashGrid
          • RollbackManager (Pro Feature)
        • Transports
          • FishyWebRTC
          • Bayou
          • FishyEOS (Epic Online Services)
          • FishyFacepunch (Steam)
          • FishyRealtime
          • FishySteamworks (Steam)
          • FishyUnityTransport
          • Multipass
          • Tugboat
          • Yak (Pro Feature)
        • Prediction
          • Network Collider
            • NetworkCollision
            • NetworkCollision2D
            • NetworkTrigger
            • NetworkTrigger2D
          • OfflineRigidbody
          • PredictedOwner
          • PredictedSpawn
        • Utilities
          • Tick Smoothers
            • NetworkTickSmoother
            • OfflineTickSmoother
          • MonoTickSmoother [Obsolete]
          • DetachableNetworkTickSmoother [Obsolete]
          • BandwidthDisplay
          • DefaultScene
          • PingDisplay
        • Authenticator
        • ColliderRollback
        • NetworkAnimator
        • NetworkBehaviour
        • NetworkTransform
        • NetworkObject
        • NetworkObserver
      • InstanceFinder
      • Ownership
        • Using Ownership To Read Values
      • Spawning and Despawning
        • Predicted Spawning
        • Nested NetworkObjects
        • Object Pooling
      • Components
      • NetworkBehaviour
      • NetworkObjects
      • Attributes, Quality of Life
      • Remote Procedure Calls
        • Broadcast
      • SyncTypes
        • Customizing Behavior
        • SyncVar
        • SyncList
        • SyncHashSet
        • SyncDictionary
        • SyncTimer
        • SyncStopwatch
        • Custom SyncType
      • Observers
        • Modifying Conditions
        • Custom Conditions
      • Automatic Serializers
      • Custom Serializers
        • Interface Serializers
        • Inheritance Serializers
      • Addressables
      • Scene Management
        • Scene Events
        • Scene Data
          • SceneLookupData
          • SceneLoadData
          • SceneUnloadData
        • Loading Scenes
        • Unloading Scenes
        • Scene Stacking
        • Scene Caching
        • Scene Visibility
        • Persisting NetworkObjects
        • Custom Scene Processors
          • Addressables
      • Transports
        • Multipass
      • Prediction
        • What Is Client-Side Prediction
        • Configuring PredictionManager
        • Configuring TimeManager
        • Configuring NetworkObject
        • Offline Rigidbodies
        • Interpolations
        • Creating Code
          • Controlling An Object
          • Non-Controlled Object
          • Understanding ReplicateState
            • Using States In Code
            • Predicting States In Code
          • Advanced Controls
        • Custom Comparers
        • PredictionRigidbody
        • Using NetworkColliders
      • Lag Compensation
        • States
        • Raycast
        • Projectiles
    • Server Hosting
      • Edgegap - Official Partner
        • Getting Started with Edgegap
      • Hathora
        • Getting Started with Hathora
      • Amazon Web Services (AWS)
        • Getting Started with AWS
    • API
Powered by GitBook
On this page
  • Spawning With Ownership
  • Changing Or Adding Ownership
  • Removing Ownership
  • Checking Ownership
  1. Manual
  2. Guides

Ownership

PreviousInstanceFinderNextUsing Ownership To Read Values

Last updated 3 months ago

Ownership is a term you will see and use very frequently throughout your development with Fish-Net. There can be only one owner, and ownership dictates which client has control over an object. It's important to know that an object does not always have an owner, and that ownership changes must be completed by the server.

When a client owns an object they are considered the rightful user to take actions on the object, such as moving a character or using a weapon on that character. You might also want to give a client temporary ownership over world objects, such as using a turret in your scene.

There are several ways to give ownership to a client. The first is spawning an object with a specific connection, or client, as the owner. There is an example below, but you may also see for more information on this.

Spawning With Ownership

Gameobject go = Instantiate(_yourPrefab);
InstanceFinder.ServerManager.Spawn(go, ownerConnection);

Changing Or Adding Ownership

If an object is already spawned you may give or take ownership for that object at anytime. The example below shows how to give ownership to a connection. Previous owners will be replaced with the newOwner. Both the previous and new owner, as well the server can receive a callback indicating that the owner status has changed. See for more details.

networkObject.GiveOwnership(newOwnerConnection);

Removing Ownership

You can also remove ownership from a client on any object at any time.

networkObject.RemoveOwnership();

As mentioned an owner is a client, commonly one that has control over an object. You can verify that you own an object by using the IsOwner property in your script. Your script must inherit from to use this. Here's a demonstration of only moving a character if the client is an owner of the object.

private void Update()
{
    if (base.IsOwner)
    {
        float hor = Input.GetAxisRaw("Horizontal");
        float ver = Input.GetAxisRaw("Vertical");
        transform.position += new Vector3(hor, 0f, ver);
    }
}

Checking Ownership

Ownership can be checked a variety of ways. These can all be checked on the NetworkObject or a NetworkBehaviour.

//Is true if the local client owns the object.
base.IsOwner;
//Returns the current owner NetworkConnection.
//This can be accessible on clients even if they do not own the object
//so long as ServerManager.ShareIds is enabled. Sharing Ids has absolutely no
//security risk.
base.Owner;
//True if the local client owns the object, or if
//is the server and there is no owner.
base.IsController

The above code will only move the transform if the client has ownership. Commonly when paired with and Client Authoritative, this will relay that movement to the server, and the server will send it to other clients.

Spawning and Despawning
NetworkBehaviour Callbacks
NetworkBehaviour
Network Transform