How to dynamically set Mouse Sensitivity?

I need to use a Slider to control the mouse sensitivity. I tried to use the "UnityInput.LookSensitivity.Set(sliderValue, sliderValue)" method but it didn't work.

What method should I use?
 
LookSensitivity has both a getter and a setter so you can use that.
"UnityInput.LookSensitivity.GetHashCode()", "UnityInput.LookSensitivity.GetType()", I Only find these two "Get" function, they have nothing to do with sensitivity.

"UnityInput.LookSensitivity.Set()", I Only find this one set function, I tried to give it a value in the 0-4 range, but it didn't work.
 
You can set the property directly:

Code:
m_PlayerInput.LookSensitivity = Vector2.zero;

1. I know where the problem is. My "Look Vector Mode" is using "Unity Smoothed", the sensitivity of this mode cannot be changed by "m_PlayerInput.LookSensitivity = Vector2.zero;".

Can the sensitivity of this mode be dynamically changed?

2.How to adjust the IK of the finger? My character doesn't have a separate hand model, and the finger IK is incorrect when he holds the gun. I tried to modify it in "Character IK.cs" but did not find the properties of the finger IK. I tried to directly modify the character's finger root in run mode, but it didn't work.

20181122212935.png
 
Last edited:
Can the sensitivity of this mode be dynamically changed?
My guess is that this relates to the state overriding the value so you could add the [NonSerialized] attribute to the property to prevent the states from overriding it.

2.How to adjust the IK of the finger? My character doesn't have a separate hand model, and the finger IK is incorrect when he holds the gun. I tried to modify it in "Character IK.cs" but did not find the properties of the finger IK. I tried to directly modify the character's finger root in run mode, but it didn't work.
Unity's IK system doesn't allow for finger IK. That looks like it could be a humanoid bone mapping issue.
 
My guess is that this relates to the state overriding the value so you could add the [NonSerialized] attribute to the property to prevent the states from overriding it.


Unity's IK system doesn't allow for finger IK. That looks like it could be a humanoid bone mapping issue.

1.I also didn't find the "left/right hand IK". Can these two IKs be adjusted? I tried remapping, but it didn't help much. These are lowpoly models, and the hand models are not detailed.

Is there a plan to integrate Final IK? I need a way to solve the IK problem in my hands and arms.

2.Is it impossible to use the first person weapon without "First Person Objects"? I want to use the third person's arm directly in the first person state.
 
Last edited:
Hello there, I am currently having the same issue.
I am able to set the Look Sensitivity, but upon zooming in and zooming out, the look sensitivity value gets set to that of the Default state.
So the changes only persist until the player zooms.


Can you please elaborate on this point?

My guess is that this relates to the state overriding the value so you could add the [NonSerialized] attribute to the property to prevent the states from overriding it.

I tried creating a preset called "DefaultOverride" so that I could try to update the preset's Look Sensitivity values.
However, it seems Preset.UpdateValues() does not do what it claims to do, as I get the following error when calling it for my DefaultOverride state:

Here is my code that references it:
C#:
void setMouseSensitivity()
    {
        //TODO: playerInput overrides the new value when a zoom occurs. Sensitivity bound to some state triggered by zoom or unzoom.
        // The sensitivity goes back to default value of 2.
        float mouseSense;
        string senseText = dT_MouseSensitivity.text;
        mouseSense = float.Parse(senseText, CultureInfo.InvariantCulture);

        Vector2 mouseSenseVector = new Vector2(mouseSense, mouseSense);
        playerInput.LookSensitivity = mouseSenseVector;

        foreach(State state in playerInput.States)
        {
            if(state.Name == "DefaultOverride")
            {
                state.Preset.UpdateValue();
            }
        }
    }

Here is the error I get:

Code:
Error: Unable to retrieve an updated value - the Get method is null.
UnityEngine.Debug:LogError(Object)
Opsive.UltimateCharacterController.StateSystem.GenericDelegate`1:UpdateValue() (at Assets/Opsive/UltimateCharacterController/Scripts/StateSystem/Preset.cs:251)
Opsive.UltimateCharacterController.StateSystem.Preset:UpdateValue() (at Assets/Opsive/UltimateCharacterController/Scripts/StateSystem/Preset.cs:86)
OptionsManager:setMouseSensitivity() (at Assets/Scripts/Game Management/OptionsManager.cs:44)
OptionsManager:saveOptions() (at Assets/Scripts/Game Management/OptionsManager.cs:26)
UnityEngine.EventSystems.EventSystem:Update() (at F:/Program Files/Unity Installations/2019.2.11f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:377)
 
Last edited:
If you are changing the value at runtime to a non-preset value you won't want to use the state system. You'll want to manage the zoom value yourself instead of using the state system.
 
Hi Justin!

With the suggestion of another community member (DankP3), I think I have come up with a solution that works fairly cleanly.
On top of being able to change mouse sensitivity via options, I want to be able to alter mouse sensitivity even if using raw look vector mode.

So I created a class that inherits from UnityInput. It creates some [NonSerialized] float values for persistent mouse sensitivity.

1575050049616.png

Then, it overrides UpdateLookVector() to tack on the multipliers at the end of PlayerInput.UpdateLookVector().
When done like this, it means that I can also set persistent zoom sensitivity.
However, this means that I had to alter the function definition of PlayerInput.UpdateLookVector() to have"protected virtual".
1575050233760.png

Do you think we could include this change in future updates?
Or perhaps even add this persistent mouse sensitivity setting as a feature to the UnityInput class?

Changing mouse sensitivity is very important for FPS games, perhaps it is one of the most important settings.
It shouldn't be so difficult to be able to set up this option for the player.

Please let me know, thanks.
 
I'm not completely following the issue. You can modify the mouse sensitivity at runtime if you don't have any states that modify the sensitivity. Isn't this what you are going for?
 
I thought that all properties in the component would be reverted to the Default State when Default State is reached, not just the ones that were modified most recently by a state change.
So basically, all I had to do was remove most of the states that were in the UnityInput component...
Damn, it seems that I had been led down a rabbithole.

I had believed this was the case for three reasons:
1. My tests made it seem like this was the case, since I forgot that my DefaultOverride state was still in place from my initial attempt to rectify the issue. (I was trying to modify a the DefaultOverride preset programatically)

2. Additionally, I had assumed that the Aim states in UnityInput were necessary for functionality of the zoom, but upon closer inspection, I saw that modifying look sensitivity was literally all they did. I was trying to work around them.

3. I had assumed from this comment that the property overriding was inevitable or necessary, since it had suggested the use of the [NonSerialized] attribute to prevent overriding.
My guess is that this relates to the state overriding the value so you could add the [NonSerialized] attribute to the property to prevent the states from overriding it.

Well, with that sorted out, I guess I took a roundabout route...

However, I still want to be able to change look sensitivity without having to use "smoothed" vector look mode.
Would it be reasonable to ask for the function definition of PlayerInput.UpdateLookVector() to include "protected virtual" in future updates anyways?
 
Last edited:
I thought that all properties in the component would be reverted to the Default State when Default State is reached, not just the ones that were modified most recently by a state change.
It will start at the default preset value, but if no presets modify the property then you can manually change the value as you please. It will not continue to adjust the property.

Would it be reasonable to ask for the function definition of PlayerInput.UpdateLookVector() to include "protected virtual" in future updates anyways?
If you set LookVectorMode to Manual then you have full control and there's no need to override UpdateLookVector. UpdateLookVector doesn't do anything when the LookVectorMode is Manual.
 
Last edited:
Just to make sure i understand this before i try any of it, if i want to use the state system on the input component (eg. adjusting look sensitivity to reduce movement when aiming), but also want the player to set the general look sensitivity they are comfortable with, does not introduction of a user adjusted multiplier solve this issue simply?
 
Top