Course contentsShow
← Unity Game Development
Lesson 114 of 8282. Scripting and LifecycleFree lesson

Managing Input Conflicts with Action Policies

Learners will implement logic to prioritize or disable inputs when multiple systems compete for player control simultaneously.

In this lesson, you will learn how to create "Action Policies" to ensure your game remains playable when multiple systems compete for player input at the same time.

The Conflict Problem

Imagine your player is walking through the world, but suddenly a dialogue box pops up. If your character continues to walk while you are trying to click through the conversation, your input is fighting for two different results. To solve this, we use an Action Policy—a simple rule-set that tells our input systems which actions are allowed to run based on the current "game state."

Implementing a State-Based Policy

Instead of letting every script listen to inputs all the time, we create a central authority that tracks whether the player is in "Free Roam" or "Menu" mode.

You can implement this using a simple bool or an enum variable. Before your movement script processes input, it checks the policy:

public class PlayerController : MonoBehaviour
{
    public bool IsInputDisabled; // The Policy Gate

    void Update()
    {
        // Check the policy before executing movement logic
        if (IsInputDisabled) return;

        // Process movement input here...
    }
}

Prioritizing Inputs

When you use the Input System, you can also manage conflicts by enabling or disabling Action Maps. For example, when the player opens a UI, you can call playerActionMap.Disable() and uiActionMap.Enable(). This ensures that your keyboard buttons don't accidentally trigger a "jump" action while you are navigating a menu.

By creating these "gates" or toggles, you stop your scripts from overlapping. Think of it like a traffic light: only one system (the road or the UI) gets the "green light" to interpret the player's button presses at any given moment. This prevents the player from unintentionally moving the character while they are trying to manage their inventory or read a quest log.

Key Takeaway: An Action Policy acts as a gatekeeper that checks the game's current state before allowing specific inputs to trigger, preventing conflicting actions from occurring simultaneously.