Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created September 2, 2025 10:15
Show Gist options
  • Save unitycoder/d0c25b07fc2d6974925955176b74ae89 to your computer and use it in GitHub Desktop.
Save unitycoder/d0c25b07fc2d6974925955176b74ae89 to your computer and use it in GitHub Desktop.

Revisions

  1. unitycoder created this gist Sep 2, 2025.
    40 changes: 40 additions & 0 deletions SimpleController_UsingActionAsset.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    // example script from Unity about this issue https://issuetracker.unity3d.com/issues/the-new-input-system-is-not-detecting-clicks-when-under-heavy-load

    using UnityEngine;

    // Use action set asset instead of lose InputActions directly on component.
    public class SimpleController_UsingActionAsset : MonoBehaviour
    {
    private SimpleControls m_Controls;
    Vector3 m_MovementSum = Vector3.zero;
    public float speed = 10f;

    public void Awake()
    {
    m_Controls = new SimpleControls();
    m_Controls.gameplay.move.performed += (callbackContext) => Sum(callbackContext.ReadValue<Vector2>());
    }
    public void Update()
    {
    var move = m_Controls.gameplay.move.ReadValue<Vector2>();
    if (move != Vector2.zero )
    {
    // Calculate sum for the callback's and apply that here.
    Move(move);
    m_MovementSum = Vector3.zero;
    }
    else if (m_MovementSum != Vector3.zero && m_Controls.gameplay.move.WasPressedThisFrame())
    {
    Move(m_MovementSum);
    m_MovementSum = Vector3.zero;
    }
    }
    private void Move(Vector3 move)
    {
    transform.Translate(move * speed * Time.deltaTime);
    }
    private void Sum(Vector2 direction)
    {
    m_MovementSum += new Vector3(direction.x, direction.y, 0);
    }
    }