Hover state broken in 1.0.0-preview.8

I’m using Unity 2020.1.4f1 with UIToolkit 1.0.0-preview.8 and the latest Input system package (1.1.0-preview.1, but this also happened with the verified 1.0.0 input package). UI Builder is 1.0.0-preview.5, although I doubt this is related in this case.

In runtime, when moving the mouse over a visual element, the pseudo state of the element is constantly changing between “None” and “Hover”. It doesn’t matter if any mouse buttons are pressed, so I’m not sure if this issue is related to this one: [Input System] Hover events only work when a mouse button is pressed

Is this a known issue?

Hello,

Yes we’ve just uncovered this issue as well. Here is the public case number:

Thanks

1 Like

I have another problem with hover states: Same Versions but old input system:
I have a Container-Visual Element on which i add other VisualElements and remove them. When a element is removed while “hover” is active and is added again later (at a different position) the “hover” state is still on and does not go away until you enter and leave the element with the mouse again.

I am having a hover issue as well. I have a button which uses .uss and has .name:hover styling to change the background color of the button, then when the button was clicked, I animated the background color value of the same button. Unfortunately, though, once that is done, the “hover” style on the button will no longer work properly for the property that was animated, even if the hover style is removed via RemoveFromClassList() and then readded. The text color change that is automatically applied still works the same, but not the background color.

Here is what I attempted to do to fix it, but it didn’t help.

var buttonContainer = new VisualElement {style = {flexDirection = FlexDirection.Row, justifyContent = Justify.FlexEnd, marginRight = 5}};
var saveButton = new Button {text = "Save", style = {width = 120}};
saveButton.AddToClassList("saveButton");
var saveButtonOriginalColor = GetColor("#585858");
saveButton.clicked += () =>
{
    saveButton.RemoveFromClassList("saveButton");
    saveButton.AnimateBackgroundColor(startColor, saveButtonOriginalColor, 500);
    saveButton.AddToClassList("saveButton");
    SavePath();
};

------- The animation was handled with the following:

public static void AnimateBackgroundColor(this VisualElement target, Color startColor, Color endColor, int durationMs)
{
    target.experimental.animation
        .Start(new StyleValues {backgroundColor = startColor}, new StyleValues {backgroundColor = endColor}, durationMs)
        .Ease(Easing.OutQuad);
}

I also attempted to use the animation’s “onCompleted” callback to see if reapplying the style after the animation had completed might help, but still nothing. The animated color change continues to work fine, but no more hover.

Imgur: The magic of the Internet (A quick demonstration of it in action)

Thanks,
-MH

We have just released 1.0.0-preview.9 which has a fix for this issue.

2 Likes