OwnedObjects for LocalClient seems always to be 0 (because not implemented?)

Hi,

I’m currently fiddling around with NetCode for GameObjects version 1.0.0-pre.5 and I’ve set up the following scenario:

I have a SpawnManager that creates the player objects like this:

var playerObject = Instantiate(PlayerPrefab);
playerObject.gameObject.name = $"Player {clientId.ToString()}";
playerObject.SpawnAsPlayerObject(clientId, true);

Then, within the SpawnShip method of the PlayerController I do the following to spawn in the player’s visual representation:

public void SpawnShip(Vector3 position, Quaternion rotation)
{
  PDebug.Log("Spawning ship for player {0}", OwnerClientId);

  var networkShip = Instantiate(ShipPrefab, position, rotation);
  networkShip.name = $"{name}_Ship";
  networkShip.SpawnWithOwnership(OwnerClientId, true);
}

As you can see, I spawn the object with SpawnWithOwnership and I put in the OwnerClientId. Via the log I can verify that the server outputs the correct Id, so 0 for player 1 and 1 for player 2.

However, I also have this little debug UI that prints various things to the screen

GUILayout.Label("Owned Objects:" + NetworkManager.Singleton.LocalClient?.OwnedObjects?.Count);

The host outputs that it has 1 owned object, which is the additional spawned ship.
However on another client (with OwnerId 1) it reports it does not have owned objects hence being spawned with SpawnWithOwnership and id 1. I also tried using ChangeOwnership immediately, but it does not help.

Am I missing here something or do I have a misunderstanding about OwnedObjects?

I also dug a bit into the code, and I’ve found this here:

(see picture 1)

This is located in class NetworkSpawnManager. As I can see here, that on server side, OwnedObjects are tracked correctly. But on client side, this piece of code is missing.

I then went on to see the message handling of ChangeOwnership, that looks like:

(see picture 2)

on client side, the debugger did enter Line 35 and 43, so the owner is set correctly, so it only looks like the tracking of the OwnedObjects is missing on client side.

Or is that intended, that the client does not track ownership of NetworkObjects? If so, the API is misleading, because NetworkManager.Singleton.LocalClient has a property OwnedObjects.

Thanks!

Edit: For whatever reason I get an access denied error, if I try to add the pictures directly into the text as full image or thumbnails via the forum buttons. :frowning:


I have a very similar problem myself.

I started with using only the Start/Awake method to find out which are the current client’s objects, but then I thought maybe the client needs some more time to initialize itself, or something.

I ended up by putting the following in the update method.

When checking the HOST, it finds its own objects, but for the other CLIENTs the count is always zero, even though I can “physically” see in the Hierarchy that there are objects in the scene which are supposedly owned by all of the connected clients.

if (NetworkManager.Singleton.LocalClient.OwnedObjects.Count == 0) return;
        if (!ownedObjectsSet) {
            ownedObjectsSet = true;
            Debug.Log($"There are about {NetworkManager.Singleton.LocalClient.OwnedObjects.Count} owned objects on My Client...");
            foreach (var myObject in NetworkManager.Singleton.LocalClient.OwnedObjects) {
                Debug.Log($"ThisObject is: {myObject}");
                if (myObject.GetComponent<NetworkAimTarget>() == true) {
                    aimTarget = myObject;
                    Debug.Log("found object in scene.....");
                }

            }
        }

This looks like a bug from other side. Could you report a bug using the Unity bug reporter so that we can look into fixing this?

Hi Luke,

I’ve just created a new bug report. Case number: 1410393

Thanks for taking a look into it!

1 Like

Just got the mail, that this is indeed an issue being tracked here now: Unity Issue Tracker - OwnedObjects for LocalClients always shows 0

:slight_smile:

2 Likes