temporarily disable all input while camera animation plays??

Hi,

In my game menu, when you choose your player by pressing enter or mouse click, everything lights up and some fx play for 1 second before the camera moves over to another part of my 3D menu. During that second, I need all input (Mouse and Keyboard) to be unresponsive, so as to not activate player rotation and fx again.

There’s only specific examples in relation to rigidbodies and movement that I could find. Can anyone tell me how to disable all input in a coroutine?

Thank you in advance

You can set and check a boolean and explicitly ignore the events coming back from each UI element in your input handler. This is a good argument for centralizing your input processing for a given screen.

Or you can put up a solid transparent object to “eat” all the touches, but then keyboard input also works still.

Or you might also be able to grab the EventSystem object in the scene and turn it off (disable it) but I’m not sure if that might have other side effects.

2 Likes

Thanks for your reply. I found this code that describes what you mention using a boolean to ignore input, but it doesn’t work. I assume it’s because the boolean doesn’t reference input? but I’m not sure. Here’s the code:

private bool disableG; // this will be set to true or false
private void Start()
{
     disableG = false;// we start it at false
}
private void Update () {
     if (Input.anyKeyDown) // if you press down any key
     {
         if (!Input.GetKeyDown(KeyCode.G)) //and that key isn't g
         {
             disableG = true; //disable g is set to true
         }
     }
     if (!Input.anyKey) //if you're not pressing anything
     {
         disableG = false; //disable g is set to true, this will ensure if you press and release a button you'll be able to press g again even if it's in a single fram
     }
     if (Input.GetKeyDown(KeyCode.G) && disableG == false) //now we see if you're pressing g and it hasn't been disabled by pressing another button
     {
         //do stuff
     }
}

I would abstract my input to a command strategy. That way its easy to disable input globally. Also you might not want to disable all commands, so maybe implement CommandGroups. Each group can be assigned a prio. Then you can call Disable(prio: 2) and all commands with 2 or lower prio will be disabled. For example.

How do I abstract my input to a command strategy exactly?

Here’s a super-simple summary of it. This is NOT abstracted:

if (Input.GetAxis("Jump") > 0.5f)
{
  // ... do all the jump logic
}
if (Input.GetKeyDown( Keycode.Space))
{
  // do all the jump logic... again!
}

Instead, this abstracts HOW you jumped from the fact that you jumped.

The “ReadAllInputThatCanJump();” function reads keyboard, joystick, mouse, whatever, and sets the jumpCommanded boolean if commanded.

bool jumpCommanded;

void Update()
{
 jumpCommanded = false;

 ReadAllInputThatCanJump();

 // now at this point all the possible ways you can jump are reflected in the jumpCommanded boolean

 // now if you are paused, set jumpCommanded = false (referring back to your original question)

 if (jumpCommanded)
 {
  // .. do the jump logic
 }
}
1 Like

Hi Kurt, Thank you for explaining. I just don’t understand how ‘ReadAllInputThatCanJump();’ gets to be “now at this point all the possible ways you can jump are reflected in the jumpCommanded boolean”. Where does the link between the two happen?
The script I uploaded before doesn’t work, and it goes by the same logic as the example you’re explaining. I’m sure I’m asking stupid questions, but I guess I just don’t understand it.

The idea that the boolean, any made up boolean, can be set to true or false and that boolean can be linked to specific input in the input manager makes total sense. It’s where, in all this code, does the boolean link to the actual input manager? That’s where I’m confused. And again, the code I submitted doesn’t work, so the boolean “disableG” isn’t referring to anything in the input manager …

Sorry, I wasn’t clear about the above: in my example above, you can actually take the first snippet of code (the two “if” statements) and put them inside the ReadAllInputThatCanJump() function, and for the predicates (the part they do if they are true), set the boolean to true!

Then later if you find a third thing that you want to make jump (such as “shake the phone violently”) then you can add it in that one place, and all other behavior “downstream” of that boolean applies, such as when you are paused, etc.

1 Like

Ah perfect. Now I’m with you :slight_smile: Thank you for explaining.