#Issue with ownership request in Distributed Authority

1 messages · Page 1 of 1 (latest)

split karma
#

I'm making a PvP FPS with Netcode for GameObjects (v2.5.1) & Distributed Authority topology.

So basically, I have a bomb defusal game mode (like in CS2), where players can pick up a bomb.
When picking up the bomb, an ownership request is sent to the one that owns the bomb. If he already owns the bomb, it is then picked up. This ensures the one holding the bomb is also the owner of it.

This normally works fine, but after restarting the match a few times, at some point, the ownership request doesn't work anymore. Also, I can't reproduce it consistently.

On the player, we decide whether to pick up or request ownership

if (bombNetworkObject.IsOwner) {
    RequestBombPickUp(bombNetworkObject);
}
else {
    RequestBombOwnership(bombNetworkObject);
}

In case we don't have ownership, we request it (targetObject is the bomb)

private void RequestBombOwnership(NetworkObject targetObject) {
    if (!targetObject.IsRequestInProgress) {
        targetObject.RequestOwnership();
    }
}

On the bomb, we have the following code

private bool EventOwnershipRequested(ulong clientrequesting) {
    // return false in some specific scenarios

    return true;
}

private void EventOwnershipRequestResponse(NetworkObject.OwnershipRequestResponseStatus ownershiprequestresponse) {
    if (ownershiprequestresponse == NetworkObject.OwnershipRequestResponseStatus.Approved) {
        // Pick up
    }
}

Whenever the bug occurs, the client tries to request ownership here

targetObject.RequestOwnership();

with the response "RequestSent"

As the response inside EventOwnershipRequestResponse, I receive "CannotRequest". Sending the request multiple times doesn't help once it's bugged out.

Core issue is that the owner of the bomb never receives the callback EventOwnershipRequested when the bug occurs, otherwise he does.

(Bomb network object in screenshot)

Any idea what it could be?
Thanks a lot!

frozen sierra
split karma
#

nope, the request required status wasn't changed. I've even printed the different flags of Ownership to ensure at the time of calling it was still the same as in the screenshot

#

I saw a bugfix in 2.6.0, but I don't think this will adress my issue:

Distributed authority clients no longer send themselves in the ClientIds list when sending a ChangeOwnershipMessage. (#3687)

frozen sierra
#

I was gonna suggest updating to 2.7 before submitting a bug report

#

Also make sure that the ownership status isn't getting changes between clients for some reason. It could be correct for the one making the call but the owner has something different

split karma
#

Thanks, I'll double check these points, update and get back to you

split karma
frozen sierra
#

Is the bomb a scene object? I don't remember if DA treats those differently or not. It would explain why they have different network object IDs

split karma
#

No, it's instantiated and spawned. The reason there is a different network object ID is because the screenshot was made from different matches

frozen sierra
#

If everything is up to date, then I would open a GitHub issue for this

split karma
#

Ok I'll do that, thanks

split karma
# frozen sierra If everything is up to date, then I would open a GitHub issue for this

btw, aren't issues GitHub only for code improvements or bugfixes? Does it make sense to ask for support with an issue there?
https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues

GitHub

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer. - Unity-T...

frozen sierra
split karma
#

I feel like there is something wrong with restarting the game, like maybe not all network objects are cleaned up correctly.

Whenever the round ends, all players are put back to the lobby scene and have this code snippet called:

public static void DespawnNonPersistentOwnedNetworkObjects() {
    if (NetworkManager.Singleton == null || !NetworkManager.Singleton.IsClient) {
        Debug.LogWarning("NetworkManager is not initialized or this is not a client instance.");
        return;
    }

    ulong localClientId = NetworkManager.Singleton.LocalClientId;
    NetworkObject[] ownedObjects = NetworkManager.Singleton.SpawnManager.GetClientOwnedObjects(localClientId);

    foreach (NetworkObject networkObject in ownedObjects) {
        if (networkObject != null && networkObject.IsSpawned) {
            if (networkObject.gameObject.scene.name != "DontDestroyOnLoad") {
                networkObject.Despawn(false);
            }
        }
    }
}

However, it could still be a bug, so creating an issue could make sense

#

I'm having a very hard time reproducing it consistently. I've been trying to do so for weeks, but without success.

The bug usually occurs after finishing a few matches with different game modes, and at some point, after starting a new match, the bomb can't be picked up anymore by clients

frozen sierra
#

When it bugs out, can you change ownership on any other objects? I'm wondering if it's just the bomb object, or requesting ownership in general get busted