FishNet icon indicating copy to clipboard operation
FishNet copied to clipboard

Position values reset when changing authority

Open SilentDanUK opened this issue 3 years ago • 2 comments

As mentioned on Discord, when changing authority between players, the objects position values are being reset back to the position when previously owned by that player.

SilentDanUK avatar Jul 16 '22 17:07 SilentDanUK

I believe you said the server had authority, would move the object, player took authority and moved, then when server got authority back it would forget the players changes and snap-back right?

FirstGearGames avatar Jul 23 '22 00:07 FirstGearGames

Yes that is correct. I have also noticed that if the server moves the object again and the player takes authority, the object will snap to the players previously owned position then snap back to the correct position.

SilentDanUK avatar Jul 26 '22 08:07 SilentDanUK

I cannot reproduce this.

Here's the script I'm using.

using FishNet.Connection;
using FishNet.Object;
using UnityEngine;

namespace FishNet.Testing.NTAuthoritySwap
{

    public class SimpleMove : NetworkBehaviour
    {
        public float MoveRate = 5f;


        private void OnMouseDown()
        {
            if (!base.IsOwner && base.IsClient)
                GiveOwnershipToMe();
            else if (base.IsServer)
                base.RemoveOwnership();
        }

        private void Update()
        {
            if (base.IsOwner || (base.IsServer && !base.Owner.IsValid))
            {
                float hor = Input.GetAxisRaw("Horizontal");
                transform.position += new Vector3(hor, 0f, 0f) * MoveRate * Time.deltaTime;
            }
        }

        [ServerRpc(RequireOwnership = false)]
        private void GiveOwnershipToMe(NetworkConnection caller = null)
        {
              base.GiveOwnership(caller);
        }
    }


}

Here is what I tried...

attempt 1

  • Launch server + two clients.
  • Make client click other players object to take it over.
  • Move other players object.
  • Other player takes cube back over. -- positions are kept properly.

attempt 2

  • Launch server(GUI) + 1 client.
  • Remove owner on client object by clicking object on server.
  • Move object around on server.
  • Take ownership on client by clicking object. -- positions are kept properly.

FirstGearGames avatar Sep 02 '22 20:09 FirstGearGames

I just added a cube object to the scene with a network transform and simplified the code to be similar to what you posted but still get the same result. We have two computers running the editor to test. One connected as server and client and the other just a client. I have made a video with both screens, top(client) and bottom(server/client), showing the issue which can be viewed here: https://www.youtube.com/watch?v=PU6V38Ro9kw This is the simplified code we are using:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FishNet.Object;
using FishNet.Connection;

public class SetOwner : NetworkBehaviour
{
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.O))
        {
            if (!base.IsOwner && base.IsClient)
                GiveOwnershipToMe();
            else if (base.IsServer)
                base.RemoveOwnership();
        }
    }

    [ServerRpc(RequireOwnership = false)]
    private void GiveOwnershipToMe(NetworkConnection caller = null)
    {
        base.GiveOwnership(caller);
    }
}

SilentDanUK avatar Sep 04 '22 18:09 SilentDanUK

Thank you for the video. Can you please provide the exact written steps to reproduce.

Eg start with default ownership. MoveA, give A to B. Any nested objects, or objects being childed.

On Sun, Sep 4, 2022, 2:21 PM SilentDanUK @.***> wrote:

I just added a cube object to the scene with a network transform and simplified the code to be similar to what you posted but still get the same result. We have two computers running the editor to test. One connected as server and client and the other just a client. I have made a video with both screens, top(client) and bottom(server/client), showing the issue which can be viewed here: https://www.youtube.com/watch?v=PU6V38Ro9kw This is the simplified code we are using:

using System.Collections; using System.Collections.Generic; using UnityEngine; using FishNet.Object; using FishNet.Connection;

public class SetOwner : NetworkBehaviour { private void Update() { if (Input.GetKeyDown(KeyCode.O)) { if (!base.IsOwner && base.IsClient) GiveOwnershipToMe(); else if (base.IsServer) base.RemoveOwnership(); } }

[ServerRpc(RequireOwnership = false)]
private void GiveOwnershipToMe(NetworkConnection caller = null)
{
    base.GiveOwnership(caller);
}

}

— Reply to this email directly, view it on GitHub https://github.com/FirstGearGames/FishNet/issues/74#issuecomment-1236391325, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGPJC3SBUEX3BNA3YE7GY2TV4TSC5ANCNFSM53YMHRDA . You are receiving this because you commented.Message ID: @.***>

FirstGearGames avatar Sep 04 '22 19:09 FirstGearGames

Bump. Need more information to troubleshoot please.

FirstGearGames avatar Sep 11 '22 19:09 FirstGearGames

Sorry for the Delay. I didnt seem to get a notification for your previous reply.

To help test this further, we created a fresh project with only Fishnet, FishySteamworks and Steamworks.net added to the project. We added the Network Manager to the scene using Fishysteamwoks peer to peer and a cube with a network transform and the SetOwner script shown above.

These are the seps for testing:

  1. Computer A starts server and joins as client.
  2. Computer B joins as client
  3. A moves the networked cube
  4. B takes ownership of the cube (This is when A can sometimes see the object jump back to the previous position then imediately to the current position)
  5. B moves the cube
  6. A takes ownership of the cube (This is when B can sometimes see the object jump back to the previous position then imediately to the current position)
  7. A moves the cube

We then noticed that Fishnet had been updated since we first had the issue, so updated to the latest version and noticed some improvement. Instead of jumping back to the previous position, the cube would only move slightly before returning to the current position. After further testing, we found that this stops happening if we set the set the tick rate to 240 on the timemanager.

We then tested this in our original project (after updating fishnet) and had the improved results when moving the cube. However when we test the game in VR with an object that we throw between eachother, we start to see the original behaviour happeneing again but only for computer B. Ownership is changed when in contact with the other playes VR hand.

Hopefully this information is helpful but please let me know if you need any more.

SilentDanUK avatar Sep 11 '22 20:09 SilentDanUK

So there is some parenting going on? If you are parenting the object do you have synchronize parents checked on the NT?

FirstGearGames avatar Sep 12 '22 15:09 FirstGearGames

We do not change the parent of the object. The only thing that changes when the object is grabbed is the ownership and isKinematic is enabled if not the ownwer.

SilentDanUK avatar Sep 13 '22 20:09 SilentDanUK

Wanted to get back to you and let you know that I've not had a chance to setup a test environment for this report. I do wonder if the kinematic/not kinematic is causing a transform desync on the physics side. After setting kinematic and not, try calling Physics.SyncTransforms()

FirstGearGames avatar Sep 21 '22 23:09 FirstGearGames

Thank you for the suggestion but unfortunately Physics.SyncTransforms() didn't seem to make a difference.

SilentDanUK avatar Sep 22 '22 21:09 SilentDanUK

I'm really sorry I think I'm going to need a bare bone project for this. I've not been able to replicate it in any way.

FirstGearGames avatar Sep 23 '22 21:09 FirstGearGames

Closed due to inactivity. Please re-open if you have a small project I can investigate. Thanks!

FirstGearGames avatar Sep 30 '22 19:09 FirstGearGames