Mirror icon indicating copy to clipboard operation
Mirror copied to clipboard

feature request: Support for NT-R to be disabled/enabled during gameplay.

Open JesusLuvsYooh opened this issue 1 year ago • 7 comments

NT-R after being disabled (moves) enabled, loses position sync, due to the delta methods. Needs some kind of resync upon enabling.

Note older NTs and NT unreliable works with this. Noticed a few places using this method over the years, such as for pickups, vehicles, platforms etc

JesusLuvsYooh avatar Jan 03 '24 11:01 JesusLuvsYooh

Does calling ResetState from OnEnable cover this?

MrGadget1024 avatar Jan 25 '24 08:01 MrGadget1024

Does calling ResetState from OnEnable cover this?

I'l give it a try.

JesusLuvsYooh avatar Jan 25 '24 09:01 JesusLuvsYooh

Nope @MrGadget1024 Easily reproducible in tanks example. Attach NTR remove NTU, host and join via another player. On either screen disable NTR on tanks, move around, enable them. Positions remain wrong.

JesusLuvsYooh avatar Jan 25 '24 09:01 JesusLuvsYooh

Video preview. (note I'm just disabling parent NTR's here, not turret.).

https://github.com/MirrorNetworking/Mirror/assets/57072365/9526bda4-0155-425d-84db-57561b56e396

JesusLuvsYooh avatar Jan 25 '24 10:01 JesusLuvsYooh

I think I had a similar issue in one of my examples and opted to unspawn > move > respawn to work around it.

MrGadget1024 avatar Jan 25 '24 10:01 MrGadget1024

NetworkTransformBase already has this...

protected virtual void OnEnable()
{
    ResetState();

    if (NetworkServer.active)
        NetworkIdentity.clientAuthorityCallback += OnClientAuthorityChanged;
}

 protected virtual void OnDisable()
 {
     ResetState();

     if (NetworkServer.active)
         NetworkIdentity.clientAuthorityCallback -= OnClientAuthorityChanged;
 }

public virtual void ResetState()
{
    // disabled objects aren't updated anymore.
    // so let's clear the buffers.
    serverSnapshots.Clear();
    clientSnapshots.Clear();
}

MrGadget1024 avatar Jan 25 '24 11:01 MrGadget1024

Yep you cannot disable and re-enable NTR like this. Unless you can trick the OnSerialize to set 'initialState' = true. I reckon you are better off introducing another bool for OnSerialize/Deserialize to check, in order to reset the positions properly.

ninjakickja avatar Feb 02 '24 02:02 ninjakickja