A low-resolution or pixel-art 3D game often draws the world in a SubViewport and scales it up. Hovering 3D objects then stops working: mouse_entered never fires, even with a CollisionShape3D and input_ray_pickable on. In our Godot 4.7 test the main window had physics_object_picking on and a StaticBody3D under the mouse got 1 mouse_entered. Inside a SubViewport, drawn at a quarter size, the same body got 0, because the SubViewport had physics_object_picking off. After turning it on, it got 1. The script below turns it on for you and shows an outline while the mouse is over the object.
The one-line fix
On the SubViewport, tick Physics > Object Picking in the Inspector, or in code: $SubViewportContainer/SubViewport.physics_object_picking = true. Our SubViewport sat in a SubViewportContainer, which passes the mouse on to it.
The code
Put this script on a StaticBody3D or Area3D that has a CollisionShape3D. Set outline to a MeshInstance3D with a show_outline(on) function, for example the one from the same-width outline page. The script turns on physics_object_picking for the viewport it is in, then shows the outline on mouse_entered and hides it on mouse_exited.
extends CollisionObject3D
## Shows an outline while the mouse is over this body (StaticBody3D, Area3D, ...), also inside a SubViewport.
## Needs a CollisionShape3D child. outline = a MeshInstance3D with a show_outline(on) function.
@export var outline: Node
func _ready() -> void:
input_ray_pickable = true
var vp := get_viewport()
if not vp.physics_object_picking:
vp.physics_object_picking = true # a SubViewport starts with this off: no mouse_entered at all
mouse_entered.connect(_hover.bind(true))
mouse_exited.connect(_hover.bind(false))
_hover.call_deferred(false) # after the outline's own _ready
func _hover(on: bool) -> void:
if outline:
outline.show_outline(on)
What we measured
A 1 m box with a box collision shape in front of the camera, and a mouse move sent into the window from the corner to the middle of the box. The SubViewport filled the 960 × 540 window in a SubViewportContainer with stretch on and stretch_shrink at 4, so it drew at 240 × 135. Two runs gave the same numbers.
- Main window:
physics_object_pickingwas on, 1mouse_entered. - SubViewport as created:
physics_object_pickingwas off, 0mouse_entered. - The same SubViewport after turning it on: 1.
- The script in a new SubViewport: picking was on after its
_ready(), and the box got 1mouse_entered. - The script in the main window: the outline was off before the mouse came over, on right after
mouse_entered, and off right aftermouse_exited.
Related pages
- A 3D outline that stays the same width on screen
- 3D outline shader without gaps at box corners
- The PSX low-resolution look in a SubViewport
- A fade overlay that blocks button clicks
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: PD Toon World Starter Kit for Godot 4 has a toon outline that keeps the same width on screen at any distance, with a mode for cubes and hard-edged props so the corners never split.
More how-tos for PD Toon World Starter Kit for Godot 4: 3D outline shader without gaps at the corners · Get a hard cel-shaded light edge from StandardMaterial3D's Toon mode · A 3D outline that stays the same width on screen
More how-tos: Game systems
- A turned building that covers the cells it stands on
- An inventory that never loses an item and never overfills a stack
- A JSON save that loads back exactly what you saved
- Fire that spreads one cell per step, in every direction
- A pooled enemy that comes back as fresh as a new one
- An enemy that stops at the dead player and finds the respawned one
- Poison, burn and bleed that keep ticking when applied again
- XP, qi and gold that keep growing without going negative
- Count slot line wins with wilds in front
- Random directions spread evenly over a sphere or a cone
- Count a lap only when the car really went round
- Make a seed repeat: daily runs, replays and roguelike seeds
- Offline progress that counts the time the game was closed
- A chance roll without the long bad-luck streaks
- Check crafting recipes in any order, with the right counts
- Make HP and mana regen the same at any frame rate
- Damage over time with the right number of ticks
- Spawn enemies where the camera cannot see them
- Keep a chasing horde from stacking into one enemy
- Make the fish bite after the same wait at any frame rate
- Snap buildings to the right grid cell on both sides of the origin
- Make a cooking timer fire once, on time
- Pick from a weighted loot table with the right chances
- Level up as many times as the XP covers
- Walk a patrol guard to each point without overshooting
- Remove items from an Array while checking them, without skipping any
- Scatter spikes, roots or trees in a circle without overlaps
- Count and take crafting items from every stack
- Play random sounds and events without obvious repeats
- Pick the growth image so the ripe one shows exactly when the crop can be picked
- Turn a day counter into season, day and year without a day 0
- An enemy that dies once, however many hits land
- A fair shuffle you can replay
- A ghost that drives the lap at real speed
- A vision cone that does not flicker at the edge
- Move a group of units without a pile-up
- A sprinkler that waters a round patch
- A slot reel that always lands forward on the result
- A crowd of NPCs that never emote or bob in step
- A song position that moves on every frame
- Nodes your editor tool adds that stay in the scene