Skip to content

Add viewport override to 2D editor#74573

Open
KoBeWi wants to merge 1 commit into
godotengine:masterfrom
KoBeWi:fix_viewport_definitive_edition
Open

Add viewport override to 2D editor#74573
KoBeWi wants to merge 1 commit into
godotengine:masterfrom
KoBeWi:fix_viewport_definitive_edition

Conversation

@KoBeWi

@KoBeWi KoBeWi commented Mar 7, 2023

Copy link
Copy Markdown
Member

This PR supersedes #61873 with alternative approach.
Instead of enabling other viewports and fighting with the editor to make it work properly, I added a button that allows to override the default 2D editor viewport with another one.

viewport.override.mp4

I have one unresolved problem though - the overriding viewport's size must match the editor's size to display properly. Right now I'm just displaying its content with a TextureRect, but maybe I should use some different approach, idk.
I didn't make much progress for some time, so I'm opening a draft.

Closes godotengine/godot-proposals#2139
Closes godotengine/godot-proposals#5422
Closes #39387

@KoBeWi KoBeWi added this to the 4.x milestone Mar 7, 2023
@KoBeWi KoBeWi force-pushed the fix_viewport_definitive_edition branch from 3a32f19 to f87e731 Compare April 19, 2023 14:03
@KoBeWi

KoBeWi commented Apr 19, 2023

Copy link
Copy Markdown
Member Author

Ok this is somewhat finished. I fixed the viewport problems by adding more viewports. So the 2D editor structure is now SubViewportContainer -> SubViewport -> TextureRect -> current viewport.

The current viewport is still displayed inside TextureRect, but screen transform is now different. While using main viewport, the displayed viewports' transform is changed. If the viewport is overriden, the containing viewport (the one under SubViewportContainer) is transformed instead and the overriding viewport is displayed in local space. It works quite well.

godot.windows.editor.dev.x86_64_ajTVBn3MD9.mp4

I'm really surprised that selecting nodes works without any problems in this setup.

The only problem are Window nodes. For whatever reason they don't redraw when content changes and don't draw anything while invisible.

godot.windows.editor.dev.x86_64_xk6EogJICc.mp4

(I also remembered that the override button is buggy)

But it's ready to be ready for review I think.

EDIT:
Also this is funny with Camera2D

godot.windows.editor.dev.x86_64_vLvG7cbxP7.mp4

@KoBeWi KoBeWi marked this pull request as ready for review April 19, 2023 14:10
@jordanlis

Copy link
Copy Markdown

This is amazing, really need that one :)

@Variable-ind

This comment was marked as off-topic.

@Calinou

Calinou commented Jul 10, 2023

Copy link
Copy Markdown
Member

@Variable-ind Please don't bump issues without contributing significant new information. Use the 👍 reaction button on the first post instead.

@Summersay415

Copy link
Copy Markdown
Contributor

What's status of this?

@KoBeWi

KoBeWi commented Aug 30, 2023

Copy link
Copy Markdown
Member Author

Needs testing and review.

@KoBeWi KoBeWi force-pushed the fix_viewport_definitive_edition branch from f87e731 to 19649e0 Compare August 30, 2023 12:28
@YuriSizov YuriSizov requested review from a team August 30, 2023 12:29
@KoBeWi KoBeWi force-pushed the fix_viewport_definitive_edition branch from 19649e0 to cd73d6a Compare August 30, 2023 13:06
@Summersay415

Copy link
Copy Markdown
Contributor

Tested locally, works good with some caveats you mentioned. Suggestion: how about not restricting rendering outside of the overridden viewport, as in a normal, not overridden one?

@KoBeWi

KoBeWi commented Aug 30, 2023

Copy link
Copy Markdown
Member Author

This is a technical restriction. The main viewport works a bit differently - when you move around, its canvas is transformed and displays a different region. The rendering is still restricted to the viewport's size, but it has the size of the editor, so you don't see that objects outside don't render.

@akien-mga

Copy link
Copy Markdown
Member

Needs rebase, and then going around to poke people on #editor to actually get this reviewed :P

@jan-Kulpas

Copy link
Copy Markdown

Would this also work for 3D nodes with a 2D Subviewport?

@KoBeWi

KoBeWi commented Jun 9, 2024

Copy link
Copy Markdown
Member Author

No, this doesn't cover 3D.

@AndreaTerenz

Copy link
Copy Markdown

Looks really good!
But what about multiple subviewports in the same scene? Would it be a simple extension to turn the toggle button into a dropdown to select a specific subview?

@KoBeWi

KoBeWi commented Sep 16, 2024

Copy link
Copy Markdown
Member Author

Currently you have to select SubViewport node and click the button on the toolbar. You can preview any SubViewport in the scene using that.

@Calinou Calinou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, it works as expected in all rendering methods.

It even works with viewports that contain 3D nodes, as long as it's previewed within the 2D editor 🙂

image

Some feedback:

  • It's hard to distinguish between the button being disabled (when a non-Viewport node is selected), enabled, and active:
Disabled Enabled Active
image image image

I suggest using a copy of the icon that is white, so that it's more visible (and there's higher contrast between the disabled and enabled state).

  • There should be tooltip when hovering the aforementioned button. Something like this:
Viewport Override
Overrides the 2D editor view with the contents of the selected Viewport node.

This would match the tooltip of the Project Camera Override button nicely (which is right besides it).

@KoBeWi KoBeWi force-pushed the fix_viewport_definitive_edition branch from cfb57bb to 712b223 Compare September 19, 2024 21:48
@KoBeWi

KoBeWi commented Sep 19, 2024

Copy link
Copy Markdown
Member Author

The button was using old style. Changed it to use the new FlatButton:

godot.windows.editor.dev.x86_64_NaJWFVzTEP.mp4

I also added tooltips:
image
image
image

I also found a bug where main screen plugin does not receive edit(null), causing invalid button state when node is deselected. It should be fixed separately.

@kitbdev

kitbdev commented Dec 3, 2024

Copy link
Copy Markdown
Contributor

@KoBeWi KoBeWi force-pushed the fix_viewport_definitive_edition branch from 712b223 to bab2fc7 Compare December 27, 2024 15:53
@KoBeWi

KoBeWi commented Dec 27, 2024

Copy link
Copy Markdown
Member Author

Rebased, but the root viewport is bugged for some reason. Its ViewportTexture is smaller than the viewport, so the 2D editor view is cropped.

@KoBeWi KoBeWi force-pushed the fix_viewport_definitive_edition branch from bab2fc7 to 9ef9844 Compare December 27, 2024 15:55
@KoBeWi KoBeWi force-pushed the fix_viewport_definitive_edition branch from 9ef9844 to d6c169b Compare December 25, 2025 15:54
@KoBeWi KoBeWi requested review from a team as code owners December 25, 2025 15:54
@KoBeWi KoBeWi requested a review from a team December 25, 2025 15:54
@KoBeWi

KoBeWi commented Dec 25, 2025

Copy link
Copy Markdown
Member Author

Rebased and integrated with #99401

@Repiteo Repiteo requested review from a team as code owners February 17, 2026 20:11
@KoBeWi KoBeWi force-pushed the fix_viewport_definitive_edition branch from d6c169b to 25e3ce8 Compare April 28, 2026 22:56
@KoBeWi KoBeWi requested a review from a team April 28, 2026 22:56
Comment thread editor/scene/canvas_item_editor_plugin.cpp Outdated
Comment thread editor/scene/canvas_item_editor_plugin.cpp Outdated
@KoBeWi KoBeWi force-pushed the fix_viewport_definitive_edition branch from 25e3ce8 to cb2face Compare June 23, 2026 16:47

@Calinou Calinou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, it works as expected.

Some feedback:

  • The viewport icon is hard to distinguish from the background when active, due to its 1-pixel thick outline:
Image

The icon is also darker than other icons besides it. Swapping this icon for an icon with a 2-pixel thick outline would improve things significantly here.

You can use this separate icon for the toolbar, with the same brightness as other icons (ViewportOverride.svg): ViewportOverride

  • When active, the tooltip could display the name of the Viewport node that is being used as an override. Since you can select different nodes without switching active viewports, it won't always match your selection.

    • For example:

      Editor viewport is overridden to show "MySubviewport". Press to disable override.

@KoBeWi KoBeWi force-pushed the fix_viewport_definitive_edition branch from 2505770 to d54a1b6 Compare July 2, 2026 21:55
@KoBeWi

KoBeWi commented Jul 2, 2026

Copy link
Copy Markdown
Member Author

I added a dedicated Scene dock button and also fixed some bugs.

image

Some feedback:

Addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

10 participants