Netcode for Gameobjects | Update vs FixedUpdate method

private void Update()
{
    if (Input.GetKeyDown(KeyCode.T))
    {
        transform.position = Vector3.zero;
    }
}
private void FixedUpdate()
{
    if (Input.GetKeyDown(KeyCode.T))
    {
        transform.position = Vector3.zero;
    }
}

Why does changing position work in FixedUpdate method but not in Update method?

I use Character Controller for character’s movement.

9915558--1433373--upload_2024-6-29_21-34-1.png

Player Code

public class PlayerController : NetworkBehaviour
{
    [SerializeField] private float speed;
    [SerializeField] private float jumpForce;

    private float m_verticalVelocity;

    private bool m_isGrounded;

    private const float k_Gravity = -20f;

    private Vector2 m_input;

    private Animator m_animator;
    private CharacterController m_characterController;

    public override void OnNetworkSpawn()
    {
        base.OnNetworkSpawn();

        enabled = IsOwner;
    }

    private void Awake()
    {
        m_animator = GetComponent<Animator>();
        m_characterController = GetComponent<CharacterController>();
    }

    private void Update()
    {
        Jump();
    }

    private void FixedUpdate()
    {
        m_input.x = Input.GetAxisRaw("Horizontal");
        m_input.y = Input.GetAxisRaw("Vertical");

        float speed = Input.GetKey(KeyCode.LeftShift) ? this.speed * 2 : this.speed;

        Gravity();

        Vector3 movement = (transform.forward * m_input.y + transform.right * m_input.x) * speed;

        m_animator.SetBool(AnimatorHash.IsMovingHash, movement.magnitude != 0);

        m_characterController.Move((movement + m_verticalVelocity * Vector3.up) * Time.fixedDeltaTime);
        m_isGrounded = m_characterController.isGrounded;

        if (transform.position.y < -1)
        {
            transform.position = Vector3.zero;
        }
    }

    private void Jump()
    {
        if (!Input.GetKey(KeyCode.Space) || !m_isGrounded)
        {
            return;
        }

        m_isGrounded = false;
        m_verticalVelocity = jumpForce;
    }

    private void Gravity()
    {
        if (m_isGrounded)
        {
            m_verticalVelocity = k_Gravity * 0.3f;
        }
        else
        {
            m_verticalVelocity += Time.fixedDeltaTime * k_Gravity;
        }
    }
}

Like I said in the other post: Input must not be used in FixedUpdate or you will miss input events.

Thank you for the answer. Character controller was overriding position change. I only use inputs in the FixedUpdate, is there any point in writing them in the Update anyway? My jump method is inside the Update.

Yes, all Input must be handled by Update. Even for analogue input you’re skipping some of the input which can lead to unexpected motion behaviour.