You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This adds a new TwoAxisVector2Composite class, an ImputBindingComposite that converts two Axis values into a Vector2.
Some old Joystick devices don't support Vector2 output for a second Stick but do provide two Axis values representing it, so this class was made for such purposes. I am currently using it to support a PS2 controller hooked up to a third party PS2-to-PC adapter found at a thrift store; I imagine adding this class would contribute to improving developer accessibility associated with income brackets and help solve headaches sooner regarding broader controller compatibility with Unity products.
Testing status & QA
This has been tested in my unity project. It's based off the documented (and presumably tested) CustomComposite script here , with the only major change being the removal of the [InitializeOnLoad] attribute to match the pattern of other built-in composites already in this repository. I have not tested it as part of this base repository but based on comparable Composite scripts it seems unlikely to cause problems.
Overall Product Risks
Very low risk; this feature doesn't affect other aspects of the software dramatically and has very barebones functionality. It is an added utility that may require documentation updating however.
Complexity: Low
Halo Effect: Low
Comments to reviewers
N/A
Checklist
Before review:
Changelog entry added.
Explains the change in Changed, Fixed, Added sections.
For API change contains an example snippet and/or migration example.
JIRA ticket linked, example (case %%). If it is a private issue, just add the case ID without a link.
The using directives needed for Vector2, InputBindingComposite<T>, and InputSystem are wrapped in #if UNITY_EDITOR, so Player/non-Editor builds may fail to compile; only using UnityEditor; should be Editor-guarded (or fully-qualify types).
Consider whether the composite should also override EvaluateMagnitude(ref InputBindingCompositeContext) (commonly used by the Input System for actuation/magnitude decisions) to ensure correct behavior in interactions that depend on magnitude.
The changelog entry is very minimal; consider aligning it with repo conventions (punctuation, link/reference if required, and briefly stating intent/usage) so it’s useful for release notes.
The #if UNITY_EDITOR guard currently removes essential using directives in player builds, which will break compilation (e.g., Vector2 will be unresolved). Keep only using UnityEditor; behind the editor guard (or remove it entirely) and move the runtime using directives outside the conditional.
-#if UNITY_EDITOR-using UnityEditor;-using UnityEngine;+using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Layouts;
-using UnityEngine.InputSystem.Utilities;-+#if UNITY_EDITOR+using UnityEditor;
#endif
Suggestion importance[1-10]: 9
__
Why: The current code wraps essential namespaces like UnityEngine and UnityEngine.InputSystem inside a #if UNITY_EDITOR block. This will cause compilation errors in standalone builds where UNITY_EDITOR is not defined, as types like Vector2 and InputBindingComposite will be missing.
High
Prevent stripping and ensure registration
This composite can be stripped in IL2CPP/managed-stripping builds because it may only be referenced by name in bindings; then registration never runs and bindings fail at runtime. Mark the type as preserved and register in Init() directly so the runtime initialization path is explicit and survives stripping.
+[UnityEngine.Scripting.Preserve]
public class TwoAxisVector2Composite : InputBindingComposite<Vector2>
{
[InputControl(layout = "Axis")]
public int xAxis;
[InputControl(layout = "Axis")]
public int yAxis;
public override Vector2 ReadValue(ref InputBindingCompositeContext context)
{
var firstPartValue = context.ReadValue<float>(xAxis);
var secondPartValue = context.ReadValue<float>(yAxis);
- return new(firstPartValue, secondPartValue);+ return new Vector2(firstPartValue, secondPartValue);
}
- static TwoAxisVector2Composite()+ [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]+ [UnityEngine.Scripting.Preserve]+ static void Init()
{
InputSystem.RegisterBindingComposite<TwoAxisVector2Composite>();
}
-- [RuntimeInitializeOnLoadMethod]- static void Init() { } // Trigger static constructor.
}
Suggestion importance[1-10]: 7
__
Why: Adding [Preserve] and moving the registration to an explicit Init method helps prevent Unity's managed code stripping from removing the class in IL2CPP builds, ensuring the composite is correctly registered at runtime.
Medium
More suggestions
🤖 Helpful? Please react with 👍/👎 | Questions❓Please reach out in Slack #ask-u-pr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This adds a new TwoAxisVector2Composite class, an ImputBindingComposite that converts two Axis values into a Vector2.
Some old Joystick devices don't support Vector2 output for a second Stick but do provide two Axis values representing it, so this class was made for such purposes. I am currently using it to support a PS2 controller hooked up to a third party PS2-to-PC adapter found at a thrift store; I imagine adding this class would contribute to improving developer accessibility associated with income brackets and help solve headaches sooner regarding broader controller compatibility with Unity products.
Testing status & QA
This has been tested in my unity project. It's based off the documented (and presumably tested) CustomComposite script here , with the only major change being the removal of the
[InitializeOnLoad]attribute to match the pattern of other built-in composites already in this repository. I have not tested it as part of this base repository but based on comparable Composite scripts it seems unlikely to cause problems.Overall Product Risks
Very low risk; this feature doesn't affect other aspects of the software dramatically and has very barebones functionality. It is an added utility that may require documentation updating however.
Comments to reviewers
N/A
Checklist
Before review:
Changed,Fixed,Addedsections.Area_CanDoX,Area_CanDoX_EvenIfYIsTheCase,Area_WhenIDoX_AndYHappens_ThisIsTheResult.During merge:
NEW: ___.FIX: ___.DOCS: ___.CHANGE: ___.RELEASE: 1.1.0-preview.3.