question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NetworkedObject Ownership Management

See original GitHub issue

Description: The ownership lifecycle seems to have a gap in it. We have an object whose ownership we would like to pass from player to player. The ownership transfer is initiated by each individual player when specific conditions are met.

MLAPI prevents non-server clients from requesting ownership transfer. This throws an error when called on clients:

   public void ChangeOwner(ulong ownerID) {
      this.NetworkedObject.ChangeOwnership(ownerID);
    }
NotServerException: Only the server can change ownership
MLAPI.Spawning.SpawnManager.ChangeOwnership (MLAPI.NetworkedObject netObject, System.UInt64 clientId) (at C:/projects/mlapi/MLAPI/Spawning/SpawnManager.cs:207)

Additionally, setting up a server-side ownership transfer method also throws error (because I’m guessing the ulong ownerID argument is being confused with the ulong method hash and wires are getting crossed):

    public void ChangeOwner(ulong ownerID) {
      InvokeServerRpc(this.ServerRPCOwnerChange, ownerID);
    }

    [ServerRPC]
    public void ServerRPCOwnerChange(ulong ownerID) {
      this.NetworkedObject.ChangeOwnership(ownerID);
    }
NullReferenceException: Object reference not set to an instance of an object
MLAPI.NetworkedBehaviour.InvokeServerRPCLocal (System.UInt64 hash, System.UInt64 senderClientId, System.IO.Stream stream) (at C:/projects/mlapi/MLAPI/Core/NetworkedBehaviour.cs:708)
MLAPI.NetworkedBehaviour.SendServerRPCPerformance (System.UInt64 hash, System.IO.Stream messageStream, System.String channel, MLAPI.Security.SecuritySendFlags security) (at C:/projects/mlapi/MLAPI/Core/NetworkedBehaviour.cs:843)
MLAPI.NetworkedBehaviour.SendServerRPCBoxed (System.UInt64 hash, System.String channel, MLAPI.Security.SecuritySendFlags security, System.Object[] parameters) (at C:/projects/mlapi/MLAPI/Core/NetworkedBehaviour.cs:739)
MLAPI.NetworkedBehaviour.InvokeServerRpc[T1] (MLAPI.NetworkedBehaviour+RpcMethod`1[T1] method, T1 t1, System.String channel, MLAPI.Security.SecuritySendFlags security) (at C:/projects/mlapi/MLAPI/Core/RPCMethods/NetworkedBehaviour.BoxedServerRpc.cs:32)

Expected Behavior: Hoping that it’s within the scope of your intended ownership control that we can pass ownership between players and player/server somewhat willy nilly.

Environment:

  • OS: Windows 10
  • Unity Version: 2018.4.9f1
  • MLAPI Version: 11.2.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
slumtrimpetcommented, Nov 11, 2019

Yes, thank you for your support via Discord. I added a bunch more logging and found that I was adding a NetworkedObject at runtime and the order in which I was doing that was screwing up everything. The problem was 100% on my side and MLAPI is amazing. 😃 Thanks!

0reactions
TwoTenPvPcommented, Nov 7, 2019

Has this been solved?

Read more comments on GitHub >

github_iconTop Results From Across the Web

NetworkObject | Unity Multiplayer Networking
Player NetworkObjects. Player objects are an optional feature in Netcode you can use to assign a networked object to a specific client. A...
Read more >
Controlling ownership of objects and disabling ACLs for ...
Control ownership of new objects that are uploaded to your Amazon S3 bucket and disable access control lists (ACLs) for your bucket using...
Read more >
Configuring Object Ownership in Networked Photon ...
In this tutorial, you'll learn to assign and transfer ownership to GameObjects in Photon-enabled applications. This is useful because it allows a user...
Read more >
Ownership - Fish-Net: Networking Evolved
When a client owns an object they are considered the rightful user to take actions on the object, such as moving a character...
Read more >
Ownership, Unity Multiplayer with Fish-Networking - YouTube
Asset Store: https://assetstore.unity.com/packages/tools/ network /fish-net- networking -evolved-207815 Github: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found