feature request: Support for NT-R to be disabled/enabled during gameplay.
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
Does calling ResetState from OnEnable cover this?
Does calling ResetState from OnEnable cover this?
I'l give it a try.
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.
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
I think I had a similar issue in one of my examples and opted to unspawn > move > respawn to work around it.
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();
}
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.