Question on changing states and preset values RT

How are the preset default values stored when a state applies a value to a gameObject? I have a few player adjustable settings that I would like to overwrite or override the values set in the controller. I can assign the value but it seems to change back to the default value once a state uses that same component, so I am wondering if the values are stored at Start. Mainly this is for mouse sensitivity, i change the value but when the player zooms it goes back to the previous value when zoom is over.
 
You aren't able to change the value of a preset, but you can set the property manually through code. In this case you don't want to use the state system for that particular property.
 
I noticed the inspector changes the default values of the states when modified:

Code:
/// <summary>
        /// Updates the value of the default state if the game is active.
        /// </summary>
        /// <param name="states">An array of all of the states.</param>
        public static void UpdateDefaultStateValues(UltimateCharacterController.StateSystem.State[] states)
        {
            // If there is a change to the object with only the default state active then the values on the preset should be updated. This will prevent the values from
            // switching back to the default state when there is a state change.
            if (Application.isPlaying) {
                var onlyDefaultActive = true;
                for (int i = 0; i < states.Length - 1; ++i) {
                    if (states[i].Active) {
                        onlyDefaultActive = false;
                        break;
                    }
                }

                if (onlyDefaultActive && states[states.Length - 1].Preset != null) {
                    states[states.Length - 1].Preset.UpdateValue();
                }
            }
        }

so might do the same for changes in game, but if I have any problems with that I will handle manually as suggested. Thanks.


***----EDIT
Yeah just applied the same logic when a player changes the sens ingame, though I think you're right to implement it separately, because now it's just overriding the presets anyway, and an offset would be needed to handle zoom and weapon specific sens which kind of defeats the purpose. Thanks for the help.
 
Last edited:
Top