godotengine / godotengine/godot

TileMap's GetLocalMousePosition() offsets inside ViewportContainer

Open
#93,458 0 comments 0 reactions 0 assignees View on GitHub
bug topic:2d topic:input
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

- Reproducible in: v3.5.3 mono stable (latest) as well as v3.5.2 mono stable

### System information

Ubuntu 22.04.4 6.5.0-35-generic

### Issue description

Here, I am trying to create 2 sections, the game on the left side (inside a ViewportContainer) and GUI side panel on the right side.

The values of GetLocalMousePosition() in point A and C should remain the same after the window is resized. This works as intended when the TileMap is on the main Viewport. However, if I wrap the TileMap inside the ViewportContainer, the value offsets unpredictably.

![image](https://github.com/godotengine/godot/assets/67568192/9f132f4e-36c7-4ec3-b7a8-d9b72fa0bfd1)

Note: I am not sure if this is a bug

### Steps to reproduce

1. Create a new project with 2D stretch mode and keep aspect.
2. Create the following Main Scene Tree:
```
- HBoxContainer (script)
    - ViewportContainer
        - Viewport
            - TileMap
    - Control
        - ColorRect
        - Label
```
3. Print the coordinate of the GetLocalMousePosition() of the TileMap whenever a LMB is triggered.

### Minimal reproduction project (MRP)

[godot_test_map.zip](https://github.com/user-attachments/files/15935873/godot_test_map.zip)

Contributor guide

Open the contributing guide

Research direction

Start with the attached godot_test_map.zip and reproduce the scene tree using HBoxContainer, ViewportContainer, Viewport, TileMap, and Control nodes. Compare TileMap.get_local_mouse_position() on the main viewport and inside the ViewportContainer while resizing, using the reported mouse-coordinate output; done when the coordinates remain consistent as described.

Written by the indexing model from the issue text.

Assessment

Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.