Friday, October 31, 2025
spot_img

Making an attempt to outline a customized Composite to the brand new Unity Enter System however failing someplace


I am following the “Contact Samples” pattern challenge that comes with the “enter system” bundle.

In one of many pattern scene, there’s a script that defines a customized composite Binding (for instance the 2D vector composite).

I am virtually rewriting the identical scripts besides altering some inputs to be added to the composite, nevertheless it’s throwing me these errors, and since I am comparatively new to writing code do not know the best way to start fixing the problem. The handbook and the scripting API are not any assist both.

these are the errors
Making an attempt to outline a customized Composite to the brand new Unity Enter System however failing someplace

that is the instance Script that provides a customized composite.


utilizing UnityEngine;
utilizing UnityEngine.InputSystem;
utilizing UnityEngine.InputSystem.Layouts;
utilizing UnityEngine.InputSystem.Utilities;
#if UNITY_EDITOR
utilizing UnityEditor;
#endif

namespace InputSamples.Drawing
{
    /// <abstract>
    /// Easy object to comprise info for drag inputs.
    /// </abstract>
    public struct PointerInput
    {


        public bool Contact;

        /// <abstract>
        /// ID of enter sort.
        /// </abstract>
        public int InputId;

        /// <abstract>
        /// Place of draw enter.
        /// </abstract>
        public Vector2 Place;

        /// <abstract>
        /// Orientation of draw enter pen.
        /// </abstract>
        public Vector2? Tilt;

        /// <abstract>
        /// Stress of draw enter.
        /// </abstract>
        public float? Stress;

        /// <abstract>
        /// Radius of draw enter.
        /// </abstract>
        public Vector2? Radius;

        /// <abstract>
        /// Twist of draw enter.
        /// </abstract>
        public float? Twist;
    }

    // What we do in PointerInputManager is to easily create a separate motion for every enter we want for PointerInput.
    // This right here exhibits a doable various that sources all inputs as a single worth utilizing a composite. Has professionals
    // and cons. Greatest professional is that every one the controls actuate collectively and ship one enter worth.
    //
    // NOTE: In PointerControls, we're binding mouse and pen individually from contact. If we did not care about multitouch,
    //       we would not need to to that however may relatively simply bind `<Pointer>/place` and many others. Nonetheless, to supply every contact
    //       as its personal separate PointerInput supply, we have to have a number of PointerInputComposites.
    #if UNITY_EDITOR
    [InitializeOnLoad]
    #endif
    public class PointerInputComposite : InputBindingComposite<PointerInput>
    {
        [InputControl(layout = "Button")]
        public int contact;

        [InputControl(layout = "Vector2")]
        public int place;

        [InputControl(layout = "Vector2")]
        public int tilt;

        [InputControl(layout = "Vector2")]
        public int radius;

        [InputControl(layout = "Axis")]
        public int strain;

        [InputControl(layout = "Axis")]
        public int twist;

        [InputControl(layout = "Integer")]
        public int inputId;

        public override PointerInput ReadValue(ref InputBindingCompositeContext context)
        {
            var contact = context.ReadValueAsButton(this.contact);
            var pointerId = context.ReadValue<int>(inputId);
            var strain = context.ReadValue<float>(this.strain);
            var radius = context.ReadValue<Vector2, Vector2MagnitudeComparer>(this.radius);
            var tilt = context.ReadValue<Vector2, Vector2MagnitudeComparer>(this.tilt);
            var place = context.ReadValue<Vector2, Vector2MagnitudeComparer>(this.place);
            var twist = context.ReadValue<float>(this.twist);


            return new PointerInput
            {
                Contact = contact,
                InputId = pointerId,
                Place = place,
                Tilt = tilt != default ? tilt : (Vector2?)null,
                Stress = strain > 0 ? strain : (float?)null,
                Radius = radius.sqrMagnitude > 0 ? radius : (Vector2?)null,
                Twist = twist > 0 ? twist : (float?)null,
            };
        }

        #if UNITY_EDITOR
        static PointerInputComposite()
        {
            Register();
        }

        #endif

        [RuntimeInitializeOnLoadMethod]
        personal static void Register()
        {
            InputSystem.RegisterBindingComposite<PointerInputComposite>();
        }
    }
}


and that is my code for my customized composite:


utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
utilizing UnityEngine.InputSystem;
utilizing UnityEngine.InputSystem.Controls;
utilizing UnityEngine.InputSystem.Utilities;
utilizing UnityEngine.InputSystem.Layouts;
#if UNITY_EDITOR
utilizing UnityEditor;
#endif


public struct myPointerInput
{
    public bool Press;
    public int PressCount;
    public Vector2 Place;
    public Vector2 Delta;
    public Vector2? Radius;

    //contact particular
    public bool? Faucet;
    //public UnityEngine.InputSystem.TouchPhase? part;
    public Vector2? StartPosition;
    public float? StartTime;

    //mouse Particular
    public Vector2? Scroll;
}




#if UNITY_EDITOR
[InitializeOnLoad]
#endif
public class MyPointerInput : InputBindingComposite<myPointerInput>
{
    [InputControl(layout = "Button")]
    public int press;
    [InputControl(layout = "Integer")]
    public int pressCount;
    [InputControl(layout = "Vector2")]
    public int place;
    [InputControl(layout = "Vector2")]
    public int delta;
    [InputControl(layout = "Vector2")]
    public int radius;

    //contact particular
    [InputControl(layout = "Button")]
    public int faucet;
    //[InputControl(layout = "TouchPhase")]
    //public UnityEngine.InputSystem.TouchPhase part;
    [InputControl(layout = "Vector2")]
    public int startPosition;
    [InputControl(layout = "Double")]
    public int startTime;

    //mouse Particular
    [InputControl(layout = "Vector2")]
    public int scroll;



    public override myPointerInput ReadValue(ref InputBindingCompositeContext context)
    {
        var press = context.ReadValueAsButton(this.press);
        var pressCount = context.ReadValue<int>(this.pressCount);
        var place = context.ReadValue<Vector2, Vector2MagnitudeComparer>(this.place);
        var delta = context.ReadValue<Vector2, Vector2MagnitudeComparer>(this.delta);
        var radius = context.ReadValue<Vector2, Vector2MagnitudeComparer>(this.radius);

        var faucet = context.ReadValueAsButton(this.faucet);
        //var part = context.ReadValue<UnityEngine.InputSystem.TouchPhase>(this.part);
        var startPosition = context.ReadValue<Vector2, Vector2MagnitudeComparer>(this.startPosition);
        var startTime = context.ReadValue<float>(this.startTime);

        var scroll = context.ReadValue<Vector2, Vector2MagnitudeComparer>(this.scroll);



        return new myPointerInput
        {
            Press = press,
            PressCount = pressCount,
            Place = place,
            Delta = delta,
            Radius = radius.sqrMagnitude > 0 ? radius : (Vector2?)null,
            //Faucet = faucet,
            StartPosition = startPosition,
            StartTime = startTime,
            Scroll = scroll
        };
    }

#if UNITY_EDITOR
    static MyPointerInput()
    {
        Register();
    }
#endif

    [RuntimeInitializeOnLoadMethod]
    personal static void Register()
    {
        InputSystem.RegisterBindingComposite<myPointerInput>();
    }


}


these are the errors in Textual content kind:

ArgumentException: Do not know the best way to convert PrimitiveValue to 'Object'
Parameter identify: sort
UnityEngine.InputSystem.Utilities.PrimitiveValue.ConvertTo (System.TypeCode sort) (at Library/PackageCache/com.unity.inputsystem@1.0.0/InputSystem/Utilities/PrimitiveValue.cs:227)
UnityEngine.InputSystem.Utilities.NamedValue.ConvertTo (System.TypeCode sort) (at Library/PackageCache/com.unity.inputsystem@1.0.0/InputSystem/Utilities/NamedValue.cs:28)
UnityEngine.InputSystem.Editor.Lists.ParameterListView.Initialize (System.Sort registeredType, UnityEngine.InputSystem.Utilities.ReadOnlyArray`1[TValue] existingParameters) (at Library/PackageCache/com.unity.inputsystem@1.0.0/InputSystem/Editor/AssetEditor/ParameterListView.cs:146)
UnityEngine.InputSystem.Editor.InputBindingPropertiesView.InitializeCompositeProperties () (at Library/PackageCache/com.unity.inputsystem@1.0.0/InputSystem/Editor/AssetEditor/InputBindingPropertiesView.cs:194)
UnityEngine.InputSystem.Editor.InputBindingPropertiesView.DrawGeneralProperties () (at Library/PackageCache/com.unity.inputsystem@1.0.0/InputSystem/Editor/AssetEditor/InputBindingPropertiesView.cs:69)
UnityEngine.InputSystem.Editor.PropertiesViewBase.DrawGeneralGroup () (at Library/PackageCache/com.unity.inputsystem@1.0.0/InputSystem/Editor/AssetEditor/PropertiesViewBase.cs:59)
UnityEngine.InputSystem.Editor.PropertiesViewBase.OnGUI () (at Library/PackageCache/com.unity.inputsystem@1.0.0/InputSystem/Editor/AssetEditor/PropertiesViewBase.cs:39)
UnityEngine.InputSystem.Editor.InputActionEditorWindow.DrawPropertiesColumn (System.Single width) (at Library/PackageCache/com.unity.inputsystem@1.0.0/InputSystem/Editor/AssetEditor/InputActionEditorWindow.cs:699)
UnityEngine.InputSystem.Editor.InputActionEditorWindow.OnGUI () (at Library/PackageCache/com.unity.inputsystem@1.0.0/InputSystem/Editor/AssetEditor/InputActionEditorWindow.cs:637)
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo tradition) (at <437ba245d8404784b9fbab9b439ac908>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the goal of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo tradition) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <437ba245d8404784b9fbab9b439ac908>:0)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at <78f1ad0f25c84e3ca853e639f50d95f5>:0)
UnityEditor.HostView.Invoke (System.String methodName) (at <78f1ad0f25c84e3ca853e639f50d95f5>:0)
UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition, UnityEngine.Rect viewRect) (at <78f1ad0f25c84e3ca853e639f50d95f5>:0)
UnityEditor.DockArea.DrawView (UnityEngine.Rect viewRect, UnityEngine.Rect dockAreaRect) (at <78f1ad0f25c84e3ca853e639f50d95f5>:0)
UnityEditor.DockArea.OldOnGUI () (at <78f1ad0f25c84e3ca853e639f50d95f5>:0)
UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Occasion evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Motion onGUIHandler, System.Boolean canAffectFocus) (at <3736d7cfd1f845a5922f99478cb469e7>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)  
GUI Error: You might be pushing extra GUIClips than you might be popping. Ensure that they're balanced.
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)  
  ArgumentException: Getting management 1's place in a bunch with just one controls when doing repaint
Aborting
UnityEngine.GUILayoutGroup.GetNext () (at <817eebdd70f8402280b9cb11fff8b976>:0)
UnityEngine.GUILayoutUtility.DoGetRect (System.Single minWidth, System.Single maxWidth, System.Single minHeight, System.Single maxHeight, UnityEngine.GUIStyle model, UnityEngine.GUILayoutOption[] choices) (at <817eebdd70f8402280b9cb11fff8b976>:0)
UnityEngine.GUILayoutUtility.GetRect (System.Single minWidth, System.Single maxWidth, System.Single minHeight, System.Single maxHeight, UnityEngine.GUIStyle model, UnityEngine.GUILayoutOption[] choices) (at <817eebdd70f8402280b9cb11fff8b976>:0)
UnityEditor.EditorGUILayout.GetControlRect (System.Boolean hasLabel, System.Single peak, UnityEngine.GUIStyle model, UnityEngine.GUILayoutOption[] choices) (at <78f1ad0f25c84e3ca853e639f50d95f5>:0)
UnityEditor.EditorGUILayout.Popup (UnityEngine.GUIContent label, System.Int32 selectedIndex, UnityEngine.GUIContent[] displayedOptions, UnityEngine.GUIStyle model, UnityEngine.GUILayoutOption[] choices) (at <78f1ad0f25c84e3ca853e639f50d95f5>:0)
UnityEditor.EditorGUILayout.Popup (UnityEngine.GUIContent label, System.Int32 selectedIndex, UnityEngine.GUIContent[] displayedOptions, UnityEngine.GUILayoutOption[] choices) (at <78f1ad0f25c84e3ca853e639f50d95f5>:0)
UnityEngine.InputSystem.Editor.InputBindingPropertiesView.DrawGeneralProperties () (at Library/PackageCache/com.unity.inputsystem@1.0.0/InputSystem/Editor/AssetEditor/InputBindingPropertiesView.cs:72)
UnityEngine.InputSystem.Editor.PropertiesViewBase.DrawGeneralGroup () (at Library/PackageCache/com.unity.inputsystem@1.0.0/InputSystem/Editor/AssetEditor/PropertiesViewBase.cs:59)
UnityEngine.InputSystem.Editor.PropertiesViewBase.OnGUI () (at Library/PackageCache/com.unity.inputsystem@1.0.0/InputSystem/Editor/AssetEditor/PropertiesViewBase.cs:39)
UnityEngine.InputSystem.Editor.InputActionEditorWindow.DrawPropertiesColumn (System.Single width) (at Library/PackageCache/com.unity.inputsystem@1.0.0/InputSystem/Editor/AssetEditor/InputActionEditorWindow.cs:699)
UnityEngine.InputSystem.Editor.InputActionEditorWindow.OnGUI () (at Library/PackageCache/com.unity.inputsystem@1.0.0/InputSystem/Editor/AssetEditor/InputActionEditorWindow.cs:637)
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo tradition) (at <437ba245d8404784b9fbab9b439ac908>:0)
Rethrow as TargetInvocationException: Exception has been thrown by the goal of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo tradition) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <437ba245d8404784b9fbab9b439ac908>:0)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at <78f1ad0f25c84e3ca853e639f50d95f5>:0)
UnityEditor.HostView.Invoke (System.String methodName) (at <78f1ad0f25c84e3ca853e639f50d95f5>:0)
UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition, UnityEngine.Rect viewRect) (at <78f1ad0f25c84e3ca853e639f50d95f5>:0)
UnityEditor.DockArea.DrawView (UnityEngine.Rect viewRect, UnityEngine.Rect dockAreaRect) (at <78f1ad0f25c84e3ca853e639f50d95f5>:0)
UnityEditor.DockArea.OldOnGUI () (at <78f1ad0f25c84e3ca853e639f50d95f5>:0)
UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Occasion evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Motion onGUIHandler, System.Boolean canAffectFocus) (at <3736d7cfd1f845a5922f99478cb469e7>:0)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Occasion e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Motion onGUIHandler, System.Boolean canAffectFocus) (at <3736d7cfd1f845a5922f99478cb469e7>:0)
UnityEngine.UIElements.IMGUIContainer.DoIMGUIRepaint () (at <3736d7cfd1f845a5922f99478cb469e7>:0)
UnityEngine.UIElements.UIR.RenderChainCommand.ExecuteNonDrawMesh (UnityEngine.UIElements.UIR.DrawParams drawParams, System.Boolean straightY, System.Single pixelsPerPoint, System.Exception& immediateException) (at <3736d7cfd1f845a5922f99478cb469e7>:0)
Rethrow as ImmediateModeException
UnityEngine.UIElements.UIR.RenderChain.Render (UnityEngine.Rect viewport, UnityEngine.Matrix4x4 projection, UnityEngine.UIElements.PanelClearFlags clearFlags) (at <3736d7cfd1f845a5922f99478cb469e7>:0)
UnityEngine.UIElements.UIRRepaintUpdater.DrawChain (UnityEngine.Rect viewport, UnityEngine.Matrix4x4 projection) (at <3736d7cfd1f845a5922f99478cb469e7>:0)
UnityEngine.UIElements.UIRRepaintUpdater.Replace () (at <3736d7cfd1f845a5922f99478cb469e7>:0)
UnityEngine.UIElements.VisualTreeUpdater.UpdateVisualTreePhase (UnityEngine.UIElements.VisualTreeUpdatePhase part) (at <3736d7cfd1f845a5922f99478cb469e7>:0)
UnityEngine.UIElements.Panel.UpdateForRepaint () (at <3736d7cfd1f845a5922f99478cb469e7>:0)
UnityEngine.UIElements.Panel.Repaint (UnityEngine.Occasion e) (at <3736d7cfd1f845a5922f99478cb469e7>:0)
UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <3736d7cfd1f845a5922f99478cb469e7>:0)
UnityEngine.UIElements.UIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <3736d7cfd1f845a5922f99478cb469e7>:0)
UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <817eebdd70f8402280b9cb11fff8b976>:0)

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles