Skip to content

Enhance Selectable Component with UnityEvent<SelectionState> #18

@ponttorez

Description

@ponttorez

The Problem

Currently, extending Selectable's visual feedback mechanism beyond the built-in Color Tint, Sprite Swap, and Animation transitions is overly burdensome:

  • No Standard Event: There is no Callback when UnityEngine.UI.Selectable.interactable or UnityEngine.UI.Selectable.SelectionState changes.

  • Overriding Complexity: Implementing custom transitions requires overriding Selectable.DoStateTransition(). This forces to create a lot of unnecessary logic (e.g., MyButton, MyInputField etc.) for every inherited component, which is tedious and poor practice.

  • Tweening Conflict: Custom Tweening libraries (like DOTween) cannot be adequately integrated with UnityEngine.UI.Selectable's lifecycle without complex workarounds (e.g., using Animation Event Triggers within Unity Animation System).

Proposed Solution

  • Expose SelectionState: Make the UnityEngine.UI.Selectable.SelectionState public.
Image
  • Add Event Transition Type: Introduce a new Enum member to UnityEngine.UI.Selectable.Transition - Event.
Image
  • Implement UnityEvent: Add UnityEvent<SelectionState> field to the UnityEngine.UI.Selectable component (this event should be invoked within the Selectable.DoStateTransition() method).

Example Usage

With this change, developers could easily hook up any custom logic or Tweening call directly in the Inspector:

  • Inspector: Set Transition to Event.

  • Event Setup: Drag and drop a component into the OnStateChange<SelectionState> event field.

  • Method Call: Select a method that accepts the SelectionState as a parameter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions