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.
new input system under heavy load sample script
// 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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment