If a host client sets a SyncVar field then it calls the hook.
But if a pure client sets the SyncVar field then it doesn't call the hook.
For exemple this code below, if a host client crouches then everyone would run the hook.
But if pure client crouches then everyone except the client itself runs the hook. (Which is correct behavior)
bool _isCrouching;
void SetCrouchingState(bool oldValue, bool isCrouching)
{
SetCrouchVisuals(isCrouching);
}
void Update
{
if(!base.isLocalPlayer) return;
if(wantToCrouch)
{
_isCrouching = true;
}
}```
While this is easy fixable by just doing this.
void Update
{
if(!base.isLocalPlayer) return;
if(wantToCrouch)
{
_isCrouching = true
if (!base.isServer)
SetCrouchVisuals(isCrouching);
}
}```
But wondering if there is a better way of going about this? To try to avoid code that treats a pure client and host client differently. Or maybe at least a way to handle that inside the hook function instead. Like a way of checking if the hook got called server side or client side.
I appreciate your input.