Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Disabling Input that's used in Input Provider doesn't disable Camera Movement / Rotation

Discussion in 'Cinemachine' started by IndieWafflus, Mar 18, 2022.

  1. IndieWafflus

    IndieWafflus

    Joined:
    Jul 26, 2021
    Posts:
    24
    Seems like it says here that it was fixed in 2.7.3+, but I'm using Cinemachine 2.8.4 and it isn't working for me.

    https://forum.unity.com/threads/how-can-i-disable-input-provider.1103872/

    I'm using the new Input System 1.0.2.

    I have these Camera Settings:
    upload_2022-3-18_10-40-32.png

    And then, in code, I disable the Look Input Action.
    upload_2022-3-18_10-41-6.png

    This returns (0.0, 0.0) on the "Look" Vector:
    upload_2022-3-18_10-49-10.png

    However, I still am able to rotate the Camera around (even if I end up disabling the PlayerActions themselves):


    Disabling the Input Provider Component works, but shouldn't disabling the Input that it's using supposed to work as well?

    Upon further thinking, I realized I should've been disabling the input provider action instead, so I did this:
    upload_2022-3-18_14-15-15.png

    But it seems to do nothing either (even with both player and input provider actions disabled) and I can still rotate and Zoom the Camera around.
     
    Last edited: Mar 20, 2022
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    You are correct, this wasn't fixed.
    There's a PR in flight right now that fixes it for real.
     
    IndieWafflus likes this.
  3. AndreaGalet

    AndreaGalet

    Joined:
    May 21, 2020
    Posts:
    90
    With version 2.8.6 still doesn't work for me. Unity 2021.3.3f1 WebGL
     
  4. namcap

    namcap

    Joined:
    Jan 8, 2016
    Posts:
    48
    I'm using 2.6.15 and this does not work for me either. Has the fix for this been released?
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    The bug that was fixed in 2.9.x, 2.8.6, and 2.6.15 is that when the input action itself is disabled, CinemachineInputProvider was not detecting this. Now it does. So if you're enabling and disabling the input action using InputAction.Enable() and InputAction.Disable(), you should be getting the correct results.

    The workaround of disabling CinemachineInputAxisProvider works in 2.9.x and 2.8.6, but does not work in 2.6.15.

    @AndreaGalet and @namcap What exactly doesn't work?
     
  6. namcap

    namcap

    Joined:
    Jan 8, 2016
    Posts:
    48
    Disabling the input associated with the CinemachineInputProvider does not disable the input. Cinemachine still reacts to the values of that input. In my case, this means the CinemachineFreeLookCamera still rotates even if the input is disabled.

    I tried this on both 2.6.15 and 2.8.6, and "Disable" does not work on either version.

    Code (CSharp):
    1.     public void DisableCameraInput() {
    2.         IsCameraInputEnabled = false;
    3.         controls.Input.MoveY.Disable();
    4.     }
    5.  
    6.     public void EnableCameraInput() {
    7.         IsCameraInputEnabled = true;
    8.         controls.Input.MoveY.Enable();
    9.     }
    upload_2022-6-3_8-0-40.png
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Can you send me a test project, because that's exactly what I did and it works for me.
     
  8. namcap

    namcap

    Joined:
    Jan 8, 2016
    Posts:
    48
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Thanks. But before I look at it, can you try unchecking this?

    upload_2022-6-3_13-0-21.png
     
  10. namcap

    namcap

    Joined:
    Jan 8, 2016
    Posts:
    48
    If I uncheck that, the inputs don't ever seem to register. Even if I then try to "enable" the input programmatically, it still does not register.
     
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Thanks for the project.
    I opened it and added this code to your InputUtils.cs:
    Code (CSharp):
    1.     public bool EnableInput;
    2.     private void Update()
    3.     {
    4.         if (moveAction.action.enabled != EnableInput)
    5.         {
    6.             if (EnableInput)
    7.                 EnableCameraInput();
    8.             else
    9.                 DisableCameraInput();
    10.         }
    11.     }
    This let me enable/disable the input by toggling the bool in the inspector. It worked perfectly: when the bool was enabled, the camera moved when I supplied the input. When it was disabled, the camera did not move. This worked with or without the AutoEnableInputs being checked.

    Am I misunderstanding something? What was the behaviour you were expecting?
     
    namcap likes this.
  12. namcap

    namcap

    Joined:
    Jan 8, 2016
    Posts:
    48
    Thanks for the example. That works for me as well.

    Unticking "auto enable inputs" didn't work for me because my script never enabled the inputs. But leaving it enabled, it runs after the script's "Start" method which is where I attempted to disable the input. So it would be immediately re-enabled after the disable.

    Not sure why enabling it before didn't work, but it must have been a bug on my end.

    Thanks for helping work through this! Looks like there's no Cinemachine issue.
     
    Gregoryl likes this.
  13. AndreaGalet

    AndreaGalet

    Joined:
    May 21, 2020
    Posts:
    90
    @Gregoryl I'm still having issues with it, Disabling Player action stop player from moving but the free look camera still rotate if i move my mouse, i have also tried to use the Move action as camera input on chinemachine input provider instead of Look action, result: Player correctly stop moving but camera still working
    upload_2022-6-14_16-19-7.png upload_2022-6-14_16-20-8.png
    Disabling Chinemachine input Provider correctly stop camera movement, but i don't want to do that if it is supposed to work
     
    Last edited: Jun 14, 2022
  14. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    What version of CM are you using?
    Are you sure that the CMInputProvider is using the same input action that you are disabling?
    When you click on an action in the InputProvider, does it bring up the correct action?
    Can you show an image of the InputProvider?
     
  15. AndreaGalet

    AndreaGalet

    Joined:
    May 21, 2020
    Posts:
    90
    -CM 2.8.6
    -CMInputProvider is using Player/look, which is on my only input action class that i have in the game, i'm sure that is the only one because when i set it in the input provider there was only that one.
     

    Attached Files:

  16. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    It works for me. I suspect that you have more than one Player/look action but don't realize it. CM by default uses the one that ships with the input system, inside the input package. If your game is using a local asset with similarly-named actions, you might not immediately see the difference.

    Click on this and see what comes up:

    upload_2022-6-22_14-23-48.png

    Try dragging the action that you are actually enabling/disabling into this field.
     
    Last edited: Jun 23, 2022
  17. AndreaGalet

    AndreaGalet

    Joined:
    May 21, 2020
    Posts:
    90
    I found out what was causing the issue, i created two scripts, one with the code that doesn't work and one with the code that works.
    I was creating a new instance of my inputAction so i was disabling the worng instance of inputAction, thanks for the help
     

    Attached Files:

    DonWazash and Gregoryl like this.
  18. Alvarden

    Alvarden

    Joined:
    Feb 22, 2019
    Posts:
    60
    I have this same issue with Cinemachine 2.8.6 and Input System 1.4.2 with Unity 2021.3.8f1
    I'm enabling/disabling an entire Action Map for a Pause Menu mechanic through code and while it disables the other actions (movement, interaction, etc), the only action that doesn't disable is the Camera movement and it keeps registering the input as if it wasn't disabled.

    And yes, i tested with both Auto Enable Inputs on and off, and the issue persists.

    I'm sharing my camera settings (it's an FPS camera):
     

    Attached Files:

  19. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    @Alvarden I it possible that you have the same issue as the previous poster? Click on this and make sure that the correct asset gets highlighted in the project panel. There can be multiple versions of input assets that share the same name, so it's an easy mistake to have the wrong one.

    upload_2022-8-23_14-50-39.png
     
  20. Alvarden

    Alvarden

    Joined:
    Feb 22, 2019
    Posts:
    60
    I did that, and yes, it highlights the correct asset. I even changed the name to make sure, and it's still the same.
    And no, i don't have any extra script in use that uses the Input Action, nor do i have another InputAction besides this one.
    Highlight.png
     
  21. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Can you put together a simple project that reproduces this issue? It's working properly for us when we try it.
     
  22. Alvarden

    Alvarden

    Joined:
    Feb 22, 2019
    Posts:
    60
    Ok, i tested on a brand new simple project (same packages: Input System 1.4.2, Cinemachine 2.8.6, same Unity 2021), using simple scripts for input and pause (nothing else) and this is what i got:
    • When setting the Speed Mode of the POV Cinemachine camera to Max Speed, the camera input is disabled properly, as it should be when paused:

    • However, when setting the Speed Mode of the same Cinemachine camera to Input Value Gain, that's where the bug happens: the camera input isn't disabled at all.
    This is what i got so far.
     
  23. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Can you send me the project please
     
  24. Alvarden

    Alvarden

    Joined:
    Feb 22, 2019
    Posts:
    60
    Thanks to @Gregoryl for the help. Here's the solution that he suggested:
    The cinemachine input provider in reality only uses the actual instance of the input asset (i named it TestPlayerInput in my test project), which means that it won't react to local instances created in a script. In my case, i was using local instances:

    Code (CSharp):
    1.  
    2.     private TestInputPlayer inputActions;
    3.     private TestInputPlayer.PlayerActions playerActions;
    4.     private TestInputPlayer.PauseActions pauseActions;
    5.     private TestInputPlayer.UIActions UIActions;
    6.     // Start is called before the first frame update
    7.     void Start()
    8.     {
    9.         inputActions = new TestInputPlayer();
    10.         playerActions = inputActions.Player;
    11.         pauseActions = inputActions.Pause;
    12.         UIActions = inputActions.UI;
    13.         playerActions.Enable();
    14.         UIActions.Disable();
    15.         pauseActions.Enable();
    16.         LockCursor();
    17.     }
    18.     public void PauseInput()
    19.     {
    20.         playerActions.Disable();
    21.         UIActions.Enable();
    22.         UnlockCursor();
    23.     }
    24.     public void ResumeInput()
    25.     {
    26.         playerActions.Enable();
    27.         UIActions.Disable();
    28.         LockCursor();
    29.     }
    So, instead of that, one way to actually disable the camera input is:
    Code (CSharp):
    1.  
    2.     InputActionMap playerActions;
    3.     InputActionMap pauseActions;
    4.     InputActionMap UIActions;
    5.     // Start is called before the first frame update
    6.     void Start()
    7.     {
    8.         var actions = GetComponent<PlayerInput>().actions;
    9.         playerActions = actions.FindActionMap("Player");
    10.         pauseActions = actions.FindActionMap("Pause");
    11.         UIActions = actions.FindActionMap("UI");
    12.         playerActions.Enable();
    13.         UIActions.Disable();
    14.         pauseActions.Enable();
    15.         LockCursor();
    16.     }
    17.     public void PauseInput()
    18.     {
    19.         playerActions.Disable();
    20.         UIActions.Enable();
    21.         UnlockCursor();
    22.     }
    23.     public void ResumeInput()
    24.     {
    25.         playerActions.Enable();
    26.         UIActions.Disable();
    27.         LockCursor();
    28.     }
    That actually worked for me.
     
  25. B_ware

    B_ware

    Joined:
    Mar 14, 2021
    Posts:
    7
    Hello everyone :)!
    same for me here: Cinemachine 2.9.7 and Input System 1.5.1, Unity 2022.3.0, when I disable the action map, the action inside that map which is used in Cinemachine Input Provider for rotating the camera still rotates.

    I checked and the asset for the input assigned to Input Provider is correct (I do have only one Player/Look in the project);
    I tried to disable that specific action;
    I tried disabling "Auto Enable Inputs";
    I tried changing the "Aim" of the camera to Max speed as someone in this topic suggested.
    But I still get the same result.

    I will go for disabling Cinemachine Input Provider component, but it is weird considering that this bug is considered fixed o_O.
     
  26. antoinecharton

    antoinecharton

    Unity Technologies

    Joined:
    Jul 22, 2020
    Posts:
    189
    Hello @B_ware :)

    I tried to reproduce what you described but couldn't. Here is a repro project I used. If you could change DisableInput.cs to your configuration and see if you manage to have the issue? I used Unity 2022.3.2f1 and input system 1.6.3.

    Also make sure you are not using both input system Legacy and New. You could go to Project Settings -> Player -> Active Input Handling = Input System Package (new)

    Let us know.
     

    Attached Files:

  27. stickylab

    stickylab

    Joined:
    Mar 16, 2016
    Posts:
    92


    how if disabling the script instead