docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Move the mouse to a visual element

    To move the mouse to a specified position, use the MouseMove() method from the PanelSimulator class.

    The following example shows how to move the mouse to a visual element, such as a button:

    [Test]
    public void MouseMoveExample()
    {
        // Make sure the UI is totally up to date.
        simulate.FrameUpdate();
    
        // Fetch the button
        var button = rootVisualElement.Q<Button>("MyButton");
    
        Assume.That(button.hasHoverPseudoState, Is.False);
    
        // Send events to mouse over the button.
        simulate.MouseMove(button.worldBound.center);
        simulate.FrameUpdate();
    
        Assert.That(button.hasHoverPseudoState, Is.True);
    }
    

    Additional resources

    • Drag an element from one place to another
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)