InvalidCastException When using DPad with GamePad Stick
I am using an Xbox-One controller and I was trying to use the dpad binding to set up movement with the Left Stick. However, these errors have were thrown anytime I tried to move. Unsure if this is intended or not.
Edit: After removing these bindings and running this issue popped up "A Native Collection has not been disposed, resulting in a memory leak. It was allocated at A:\Unity\2D\Playground\2D PlayGround\Library\PackageCache\[email protected]\InputSystem\Utilities\ArrayHelpers.cs:369."
Edit 2: So the issue is when I try to use an AxisDeadZone Processor on the LeftStick/Left.
Errors Error 1: InvalidCastException thrown during execution of 'Performed' callback on action 'Player/Movement' UnityEngine.Experimental.Input.LowLevel.<>c__DisplayClass6_0:<set_onUpdate>b__0(NativeInputUpdateType, Int32, IntPtr) UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, Int32, IntPtr) (at C:/buildslave/unity/build/Modules/Input/Private/Input.cs:91)
Error 2:
InvalidCastException: Specified cast is not valid.
UnityEngine.Experimental.Input.InputActionMapState.ReadValue[TValue] (System.Int32 bindingIndex, System.Int32 controlIndex, System.Boolean ignoreComposites) (at Library/PackageCache/[email protected]/InputSystem/Actions/InputActionMapState.cs:1173)
UnityEngine.Experimental.Input.InputActionMapState.ReadCompositePartValue[TValue] (System.Int32 bindingIndex, System.Int32 partNumber) (at Library/PackageCache/[email protected]/InputSystem/Actions/InputActionMapState.cs:1197)
UnityEngine.Experimental.Input.InputBindingCompositeContext.ReadValue[TValue] (System.Int32 partNumber) (at Library/PackageCache/[email protected]/InputSystem/Actions/InputBindingCompositeContext.cs:22)
UnityEngine.Experimental.Input.Composites.DpadComposite.ReadValue (UnityEngine.Experimental.Input.InputBindingCompositeContext& context) (at Library/PackageCache/[email protected]/InputSystem/Actions/Composites/DpadComposite.cs:38)
UnityEngine.Experimental.Input.InputActionMapState.ReadValue[TValue] (System.Int32 bindingIndex, System.Int32 controlIndex, System.Boolean ignoreComposites) (at Library/PackageCache/[email protected]/InputSystem/Actions/InputActionMapState.cs:1150)
UnityEngine.Experimental.Input.InputAction+CallbackContext.ReadValue[TValue] () (at Library/PackageCache/[email protected]/InputSystem/Actions/InputAction.cs:698)
RPGPlayerMovement.Movement_Performed (UnityEngine.Experimental.Input.InputAction+CallbackContext obj) (at Assets/RPG/ScriptablesObjects/Movement/RPGPlayerMovement.cs:19)
UnityEngine.Experimental.Input.InputActionMapState.CallActionListeners (UnityEngine.Experimental.Input.InputActionMap actionMap, UnityEngine.Experimental.Input.Utilities.InlinedArray1[System.Action1[UnityEngine.Experimental.Input.InputAction+CallbackContext]]& listeners, UnityEngine.Experimental.Input.InputActionMapState+TriggerState& trigger) (at Library/PackageCache/[email protected]/InputSystem/Actions/InputActionMapState.cs:896)
UnityEngine.Experimental.Input.LowLevel.<>c__DisplayClass6_0:<set_onUpdate>b__0(NativeInputUpdateType, Int32, IntPtr)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, Int32, IntPtr) (at C:/buildslave/unity/build/Modules/Input/Private/Input.cs:91)
Error 2, stack trace top 4:
InputActionMapState.cs:1173
InputActionMapState.cs:1197
InputBindingCompositeContext.cs:22
Composites/DpadComposite.cs:38
Since AxisDeadzoneProcessor is a IInputControlProcessor<float> and TValue at that point is float the cast shouldn't throw. So, processors probably has a faulty entry or an additional one.
processors is set only in line 157 and that method is called from 2 places.
Can you debug? Try and see what processors[processorStartIndex + i] evaluates to here: InputActionMapState.cs:1173. I'm not familiar with the repo or the input system yet, I'll take a look tomorrow. I hope it wasn't a minor mistake and this is a real issue, lol.
Ran into what I believe is this issue, too. From what I understand, the underlying problem here appears to be that: first the individual composite part values contributing to the composite (e.g. float) get processed, second for the actual composite value (e.g. Vector2) get processed, however, both times the same processors are used - the ones assigned to the action the composite is bound to. And if the types differ there's a problem (because the processor can only work for one type).
FWIW, for me the expected behaviour here would be to only apply action processors to the final composite value, not composite part values, and to optionally have a processor parameter for CompositeSyntax.With to specify processors for composite parts explicitly where necessary.
When binding a stick movement to a 2D Vector Composite, the Deadzone error still happens. The work around is to use bind the movement with "Leftstick" directly, instead of using a 2D Vector Composite.
Verified fix on 2019.1.0b9 with Develop (af5d4c1)