UNET update localScale

Im trying to sync the localScale between all clients however it’s not working for the host, I understand I need to use a Command to update the server, but it doesn’t work…do I have to reference which transform’s localScale is being changed in the Command using a netID or something?

public class Character : NetworkBehaviour {


    [SyncVar(hook = "OnScaleChanged")]
    public Vector3 playerLocalScale;


    public void Left() {
        _player.velocity = new Vector2(moveSpeed, _player.velocity.y);
        playerLocalScale = new Vector3(-1, 1, 1);
        transform.localScale = new Vector3(-1, 1, 1);
        CmdOnScaleChanged(playerLocalScale);
    }

    public void Right() {
        _player.velocity = new Vector2(-moveSpeed, _player.velocity.y);
        playerLocalScale = new Vector3(1, 1, 1);
        transform.localScale = new Vector3(1, 1, 1);
        CmdOnScaleChanged(playerLocalScale);

    }

    public void OnScaleChanged(Vector3 playerLocalScale) {
        transform.localScale = playerLocalScale;
        Debug.Log(netId + "changed scale");
    }

    [Command]
    public void CmdOnScaleChanged(Vector3 playerLocalScale) {
            transform.localScale = playerLocalScale;
        }
    }

The SyncVar works perfectly and syncs it for clients, however the Command doesn’t work, and thus the host does not see any localScale changes.

SOLVED used Command into RPC

Could you elaborate on what you mean by “used Command into RPC”? I’m having this same issue, and I don’t know if you mean you called a Command that called an RPC or what.

Yes, make the local player call a Command. In that command you set the localScale for the Server. And you also call a RPC and in the RPC you set the localScale aswell for all the clients.

1 Like