Skip to content

Conversation

adrian-koretski-unity3d
Copy link
Collaborator

Description

Fixing confusing menu when selecting face buttons due to aliased enum values.

Changes made

Removed aliased enum values.

Testing

Manual testing.

Risk

None.

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.
    • Jira port for the next release set as "Resolved".
  • Tests added/changed, if applicable.
    • Functional tests Area_CanDoX, Area_CanDoX_EvenIfYIsTheCase, Area_WhenIDoX_AndYHappens_ThisIsTheResult.
    • Performance tests.
    • Integration tests.
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

After merge:

  • Create forward/backward port if needed. If you are blocked from creating a forward port now please add a task to ISX-1444.

@unity-cla-assistant
Copy link

unity-cla-assistant commented Aug 13, 2024

CLA assistant check
All committers have signed the CLA.

/// The right trigger button on a gamepad.
/// </summary>
RightTrigger = 33,

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot remove these from this enum without requiring a major version revision since it would break public API for existing customers (and according to semver), hence this is not a viable way forward.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't thought of this. I re-added the aliased enum values (although I did not reset them in the other files that used them to move towards north/south/east/west). I also added a slightly modified version of the aliased enum drawer from #1862 where we can remove values from the drawer.


### Changed
- Use `ProfilerMarker` instead of `Profiler.BeginSample` and `Profiler.EndSample` when appropriate to enable recording of profiling data.
- Removed aliased values in GamepadButton enum.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not want to release a major revision due to this change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we plan to do so down the line? Perhaps mark the aliased values as depricated (I'm not sure how we go about doing this).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We basically shouldn't modify the enum at all, we should aim for a completely editor-based "fix" here. There is no functional issue with the current solution, its only confusing users from UX perspective.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense though to file an internal ticket to consider removing aliases for control enums down the line (in a major future release). I have now filed it.

@ekcoh
Copy link
Collaborator

ekcoh commented Aug 13, 2024

I would recommend considering a fix based off this one but with inlined/combined options for aliased entries? #1862

@ekcoh
Copy link
Collaborator

ekcoh commented Aug 13, 2024

Seems like @Billreyn was also considering that unless opinion has shifted, see #1862 (comment)

…ting projects. Added custom aliased enum drawer base and custom enum drawer for GamepadButton to hide aliased values.
@adrian-koretski-unity3d
Copy link
Collaborator Author

Seems like @Billreyn was also considering that unless opinion has shifted, see #1862 (comment)

I believe so. Based on our conversation, we want to display only North/South/East/West

ctx => { ++receivedCalls; };
action.Enable();

var firstState = new GamepadState {buttons = 1 << (int)GamepadButton.B};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix shouldn't have any impact on existing tests?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hence I wouldn't expect any changes to any tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is due to my first pass where I removed the aliased values. Will revert


++InputUser.listenForUnpairedDeviceActivity;

InputSystem.QueueStateEvent(gamepad, new GamepadState { leftStick = new Vector2(1, 0)}.WithButton(GamepadButton.A));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't need to change either.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is due to my first pass where I removed the aliased values. Will revert

@ekcoh
Copy link
Collaborator

ekcoh commented Sep 13, 2024

Seems like @Billreyn was also considering that unless opinion has shifted, see #1862 (comment)

I believe so. Based on our conversation, we want to display only North/South/East/West

Exactly, with emphasis on "display", hence it should be property drawer only changes as I see it.

/// </summary>
/// <remarks>
/// Identical to <see cref="Y"/> and <see cref="Triangle"/> which are the Xbox and PlayStation controller names for this button.
/// Identical to <see cref="North"/> and <see cref="North"/> which are the Xbox and PlayStation controller names for this button.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems incorrect? Referencing to the same thing

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is due to my first pass where I removed the aliased values. Will revert

Copy link
Collaborator

@ekcoh ekcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a bit more work I believe

allButtonPresses.Clear();

Release(gamepad.buttonSouth);
InputSystem.QueueStateEvent(gamepad, new GamepadState(GamepadButton.A, GamepadButton.B));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not expecting any changes needed to this file


Assert.That(gamepad.buttonEast.isPressed, Is.False);

var newState = new GamepadState {buttons = 1 << (int)GamepadButton.B};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not expecting any changes needed to this file

@@ -0,0 +1,72 @@
#if UNITY_EDITOR
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2024-09-13 at 11 09 14
Screenshot 2024-09-13 at 11 11 23
I am afraid this is not doing what its supposed to.....

The following things need to be addressed:

  • Aliased values should be part of the same entry when the inspector is displayed, e.g. "South / X / A"
  • Drop down need to allow all values to be picked, e.g. either "South / X / A" or each one individually would be fine from my perspective.
  • At the moment when selecting e.g. South, the value displayed is "North", so something with mapping is incorrect

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll go over it and make sure it behaves and displays correctly


private void ProcessDisplayNamesForAliasedEnums()
{
var enumNamesAndValues = new Dictionary<string, int>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the enum is small and we want consistency, maybe skip this base class and just move into specific GamepadButtonPropertyDrawer class and just use a big switch statement to get it right? That would be quite straightforward. Otherwise there needs to be some smartness to get the order of each aliased combination separated by slashes consistent.

…on specific to gamepad buttons. Also removed aliased values in GamepadButton enum"

This reverts commit 110e5c6.

# Conflicts:
#	Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/AliasedEnumPropertyDrawer.cs.meta
#	Packages/com.unity.inputsystem/InputSystem/Editor/PropertyDrawers/GpadButtonPropertyDrawer.cs.meta
Removed general AliasedEnumPropertyDrawer script.
Copy link
Collaborator

@lyndon-unity lyndon-unity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks reasonable, one minor recommendation, but I haven't tested it in action.
Suggest adding QA or design for a manual verification

/// Property drawer for <see cref = "GamepadButton" />
/// </summary >
[CustomPropertyDrawer(typeof(GamepadButton))]
internal class GpadButtonPropertyDrawer : PropertyDrawer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor but can you use a full name here rather than abbreviation
GpadButtonPropertyDrawer ->
GamepadButtonPropertyDrawer

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which also means renaming file and .meta

Copy link
Collaborator

@ekcoh ekcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving this to not block this PR in any way while I have limited accessability. I didn't run it on this review round so recommend checking functionality in QA pass.


### Changed
- Use `ProfilerMarker` instead of `Profiler.BeginSample` and `Profiler.EndSample` when appropriate to enable recording of profiling data.
- Removed aliased values in GamepadButton enum.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be reverted as well, suggest to change to something like e.g. "Changed representation of GamepadButton enum values in Inspector to display aliased enum values as a single item to avoid confusion around selection and aliased value display when multiple enum items map to the same numerical value."

/// Property drawer for <see cref = "GamepadButton" />
/// </summary >
[CustomPropertyDrawer(typeof(GamepadButton))]
internal class GpadButtonPropertyDrawer : PropertyDrawer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree

/// Property drawer for <see cref = "GamepadButton" />
/// </summary >
[CustomPropertyDrawer(typeof(GamepadButton))]
internal class GpadButtonPropertyDrawer : PropertyDrawer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which also means renaming file and .meta


for (var i = 0; i < enumDisplayNames.Length; ++i)
{
string enumName = enumDisplayNames[i];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assignment could be on line 40 right since overwritten for the special cases?


if (enumName != null)
{
enumNamesAndValues.Add(enumName, (int)enumValues.GetValue(i));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be moved up to the place where it is currently assigned as null?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it up a little bit. For the cases where we do not want to enter the enum into the list, I continue the for loop, eliminating the need for null/null check. The switch statement sets an string value which is then entered into the list.

@Pauliusd01
Copy link
Collaborator

Will check this today or tomorrow morning at the latest

@Pauliusd01 Pauliusd01 changed the title CHANGE: Isxb 543 Removed aliased values in Gamepad enum. CHANGE: Removed aliased values in Gamepad enum. (ISXB-543) Sep 18, 2024
Copy link
Collaborator

@Pauliusd01 Pauliusd01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entering play mode with one of these new values selected breaks inspector and throws errors. Also, the enum value does not match the one in the inspector (See debug log in screenshot, whether that's expected I dunno)

1726666305 IN-45621_-Scene-_Windows,_Mac,Linux-_Unity_6_P

-Renamed GpadButtonPropertyDrawer to GamepadButtonPropertyDrawer.
-Fixed nullref issue caused by m_EnumDisplayNames being reset when entering/exiting play mode.
-Simplified code for setting up enum list.
-Updated CHANGELOG.md
@adrian-koretski-unity3d
Copy link
Collaborator Author

Entering play mode with one of these new values selected breaks inspector and throws errors. Also, the enum value does not match the one in the inspector (See debug log in screenshot, whether that's expected I dunno)

1726666305 IN-45621_-Scene-_Windows,_Mac,Linux-_Unity_6_P

The nullref issue should be fixed now. The value being displayed will be one of the aliased enums for that value so this is to be expected.


### Changed
- Use `ProfilerMarker` instead of `Profiler.BeginSample` and `Profiler.EndSample` when appropriate to enable recording of profiling data.
- Changed representation of GamepadButton enum values in Inspector to display aliased enum values as a single item to avoid confusion around selection and aliased value display when multiple enum items map to the same numerical value.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changelog entry in the wrong version and no bug issue link

@Pauliusd01 Pauliusd01 self-requested a review September 19, 2024 13:23
@Pauliusd01
Copy link
Collaborator

@adrian-koretski-unity3d I approved too hastily, the link has to be to a public issue tracker not our internal jira lol

@adrian-koretski-unity3d adrian-koretski-unity3d merged commit ddc99ca into develop Sep 19, 2024
77 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants