SubViewport
An interface to a game world that doesn't create a window or draw to the screen directly.
An interface to a game world that doesn't create a window or draw to the screen directly.
SubViewport Isolates a rectangular region of a scene to be displayed independently. This can be used, for example, to display UI in 3D space.
Note: SubViewport is a Viewport that isn't a Window, i.e. it doesn't draw anything by itself. To display anything, SubViewport must have a non-zero size and be either put inside a SubViewportContainer or assigned to a ViewportTexture.
Note: InputEvents are not passed to a standalone SubViewport by default. To ensure InputEvent propagation, a SubViewport can be placed inside of a SubViewportContainer.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
SubViewportConstructor
public SubViewport();Properties6
RenderTargetClearModeProperty
public SubViewport.ClearMode RenderTargetClearMode { get; set; }The clear mode when the sub-viewport is used as a render target. Note: This property is intended for 2D usage.
RenderTargetUpdateModeProperty
public SubViewport.UpdateMode RenderTargetUpdateMode { get; set; }Controls render-target redrawing: Disabled keeps the last frame, Always draws continuously, and Once requests one frame. It does not pause scripts or physics. In the current build the getter retains Once after the draw even though RenderingServer has stopped repeated rendering. Assigning Once again requests another frame; do not wait for the getter to become Disabled as a completion signal.
SizeProperty
public Vector2I Size { get; set; }Viewport output size in pixels. Scaling3DScale changes internal 3D resolution separately: Size=(512,384) with scale 0.5 still yields a 512×384 GetTexture result. Change Size to resize output, accounting for UI and target dimensions.
Size2DOverrideProperty
public Vector2I Size2DOverride { get; set; }Logical 2D area in pixels. Enable Size2DOverrideStretch to stretch it into the output target. Changes canvas coordinate mapping, not the output texture Size.
Size2DOverrideStretchProperty
public bool Size2DOverrideStretch { get; set; }Enables stretching the logical Size2DOverride area into output Size. For example, a 64 by 48 canvas can fill a 128 by 96 target without changing output texture dimensions.
ViewCountProperty
public int ViewCount { get; set; }The number of view layers we are rendering to. Set this to 2 to enable stereo rendering.
Methods12
GetClearModeSubViewport.ClearMode
public SubViewport.ClearMode GetClearMode();SubViewport.ClearModeGetSizeVector2I
public Vector2I GetSize();Vector2IGetSize2DOverrideVector2I
public Vector2I GetSize2DOverride();Returns the requested Size2DOverride value. Logical 2D area in pixels. Enable Size2DOverrideStretch to stretch it into the output target. Changes canvas coordinate mapping, not the output texture Size.
Vector2IValue of Size2DOverride; account for the documented distinction between a setting and its effective result.
GetUpdateModeSubViewport.UpdateMode
public SubViewport.UpdateMode GetUpdateMode();Returns the requested RenderTargetUpdateMode value. Texture update policy. Disabled retains the frame; Always renders even without visible use; Once requests one frame. The scene getter retains Once after consumption, so it is not a completion indicator. Assign Once again to request another frame. Does not pause Entity processing.
SubViewport.UpdateModeValue of RenderTargetUpdateMode; account for the documented distinction between a setting and its effective result.
GetViewCountint
public int GetViewCount();intIsSize2DOverrideStretchEnabledbool
public bool IsSize2DOverrideStretchEnabled();Returns the requested Size2DOverrideStretch value. Enables stretching the logical Size2DOverride area into output Size. For example, a 64 by 48 canvas can fill a 128 by 96 target without changing output texture dimensions.
boolValue of Size2DOverrideStretch; account for the documented distinction between a setting and its effective result.
SetClearModevoid
public void SetClearMode(SubViewport.ClearMode mode);| Name | Type | Default |
|---|---|---|
mode | SubViewport.ClearMode | — |
SetSizevoid
public void SetSize(Vector2I size);| Name | Type | Default |
|---|---|---|
size | Vector2I | — |
SetSize2DOverridevoid
public void SetSize2DOverride(Vector2I size);Sets Size2DOverride. Logical 2D area in pixels. Enable Size2DOverrideStretch to stretch it into the output target. Changes canvas coordinate mapping, not the output texture Size.
| Name | Type | Default |
|---|---|---|
size | Vector2I | — |
sizeLogical 2D area in pixels. Enable Size2DOverrideStretch to stretch it into the output target. Changes canvas coordinate mapping, not the output texture Size.
SetSize2DOverrideStretchvoid
public void SetSize2DOverrideStretch(bool enable);Sets Size2DOverrideStretch. Enables stretching the logical Size2DOverride area into output Size. For example, a 64 by 48 canvas can fill a 128 by 96 target without changing output texture dimensions.
| Name | Type | Default |
|---|---|---|
enable | bool | — |
enableEnables stretching the logical Size2DOverride area into output Size. For example, a 64 by 48 canvas can fill a 128 by 96 target without changing output texture dimensions.
SetUpdateModevoid
public void SetUpdateMode(SubViewport.UpdateMode mode);Sets RenderTargetUpdateMode. Texture update policy. Disabled retains the frame; Always renders even without visible use; Once requests one frame. The scene getter retains Once after consumption, so it is not a completion indicator. Assign Once again to request another frame. Does not pause Entity processing.
| Name | Type | Default |
|---|---|---|
mode | SubViewport.UpdateMode | — |
modeTexture update policy. Disabled retains the frame; Always renders even without visible use; Once requests one frame. The scene getter retains Once after consumption, so it is not a completion indicator. Assign Once again to request another frame. Does not pause Entity processing.
SetViewCountvoid
public void SetViewCount(int viewCount);| Name | Type | Default |
|---|---|---|
viewCount | int | — |
SubViewport.ClearMode
| Value | Description |
|---|---|
Always = 0 | Always clear the render target before drawing. |
Never = 1 | Never clear the render target. |
Once = 2 | Clear the render target on the next frame, then switch to |
SubViewport.UpdateMode
| Value | Description |
|---|---|
Always = 4 | Always update the render target. |
Disabled = 0 | Do not update the render target. |
Once = 1 | Update the render target once, then switch to |
WhenParentVisible = 3 | Update the render target only when its parent is visible. |
WhenVisible = 2 | Update the render target only when it is visible. This is the default value. |