RectBase2D
- Last UpdatedNov 26, 2025
- 7 minute read
The RectBase2D node is an abstract node that is the base of almost all 2D user interface nodes. It cannot be used itself.
It contains all the parameters that enable placement of 2D content.
Platform support
This node is fully supported on XR-Windows platform.
It is partially supported on XR-Portable Windows, XR-Portable iOS, XR-Portable Android, and XR-P WASM platforms.
Due to different input/output management systems, the joyInputEnable, keyInputEnable and mouseInputEnable fields are not supported in the portable platforms.
|
XR-WIN |
XR-P-WIN |
XR-P-IOS |
XR-P-AND |
XR-P-WASM |
|---|---|---|---|---|
|
Full support |
Partial support |
Partial support |
Partial support |
Partial support |
|
|
|
|
|
|
Features
The main features of this new 2D content are:
-
Better integration with XR Studio Graphic Context handler.
-
Content parenting based on a parent field.
-
Support for context rendering on a Texture2D object.
Position
The 2D nodes can be positioned inside a context node, such as Context or Global, or be children of other 2D nodes.
User interaction
Most of the 2D nodes support user interaction. For this reason, the 2D nodes have been designed to automatically support interaction by mouse, keyboard, and joypad without any further activity from the developer.
In order to let the user design new interaction behaviors, there are specific fields to disable automatic interaction management for gamepad (joyInputEnable) and keyboard (keyInputEnable).
Rendering modes
RectBase2D-derived class objects can be rendered on the screen in overlay or inside a Texture2D object.
They can be used to implement simulation of terminals inside the 3D world, or to give new interaction functionalities to 3D objects.
Content types for Images
Most RectBase2D nodes will load and display images.
The following content types can be used.
|
Content type |
Description |
|---|---|
|
images |
PNG, TGA, DDS, GIF |
|
http image urls |
complete http url ="http://..." of an image |
Updating mode
By default, all 2D content is updated by the so-called dirty system.
-
When 2D content must be updated, its texture is added to the dirty system list.
-
The update of the elements in the list is managed by the dirty system trying to optimize rendering performance.
-
When elements request updating simultaneously, the 2D element update might be delayed, depending on FPS performance.
You can set the updateMode for all the RectBase2D-derived nodes.
Value
Description
dirty
Content update is managed by the dirty system.
direct
Content is instantly updated when item is visible. If content is hidden, update does not occur until item is made visible.
Setting the update mode to direct enables you to exclude items from control by the dirty management system.
Note: The updateMode parameter does not work when the 2D component is rendered in a Texture2D node, because the texture has its own refresh rate.
Size mode and anchoring
stretchToGrid
The StretchToGrid mode is the typical mode for fullscreen applications. Size and position of the 2D node are expressed in grid points.
-
Grid points are defined by the set fullscreen resolution.
-
When application is run in fullscreen, grid size and resolution are the same and the grid points correspond to pixels.
-
When the application is windowed, the same grid points are represented in smaller area size (window area). This causes the 2D node to be stretched according to the ratio between window size and grid size.
keepSize
Use keepSize mode to avoid stretching 2D interfaces.
-
When the 2D node is set to keepSize, the size and position are always expressed in pixels.
-
When content is set to keepSize, it not only keeps the size but also the position. This is done using anchorH and anchorV parameters.
For horizontal anchoring:
-
left—The content left border is kept to position.x pixels from left window border (positive values).
-
right—The content right border is kept to position.x pixels from right window border (negative values).
-
center—The content center is kept to position.x pixels from window half width (negative for going left, positive for going right)
-
none—The content positioning behaves as in stretchToGrid mode by keeping the distance from left border proportional to screen width.
For vertical anchoring:
-
top—The content top border is kept to position.y pixels from top window border (positive values).
-
bottom—The content bottom border is kept to position.y pixels from bottom window border (negative values).
-
center—The content center is kept to position.y pixels from window half height (negative for going up, positive for going down).
-
none—The content positioning behaves as in stretchToGrid mode by keeping the distance from top border proportional to screen height.
Parenting
By using the parent field, RectBase2D-derived nodes can be grouped together. See parent and children fields in the fields table below.
Children nodes will inherit the position and scale of the parent. Therefore, parenting enables you to create composite 2D interfaces that can be moved and scaled together easily.
Parented 2D interface
When creating a parented 2D GUI:
-
Set root node to keepSize sizeMode.
-
Set its anchoring.
-
Position it.
For all child nodes:
-
Set node to keepSize sizeMode.
-
Keep Top Left anchoring.
-
Position child node with an offset referred to top left position of parent.
Mouse event propagation
RectBase2D nodes can be placed one over the other to create a complex UI. They are represented according to their order.
When a mouse event happens on a point where two or more RectBase2D nodes are overlying, the event is captured only by the RectBase2D that is on top.
In some cases, you might want to propagate the mouse event to the underlying RectBase2D node. For example, if a Rect2D with an image is positioned over a Button2D, you might want the button to react to click even when the pointer is over the image. You can achieve this by setting the propagateEvent field to true.
By default, the propagateEvent is set to false for all RectBase2D nodes—with the exception of Text2D and DynamicText2D.
Note: Mouse event propagation impacts Hotspotnstances of mode2D type. This means that any RectBase2D element drawn on the 2D overlay layer with propagateEvent set to false will prevent underlying hotspot interaction.
RectBase2D fields
These are the fields for RectBase2D node. Only the node-specific fields are indicated, not fields obtained by inheritance.
Field inheritance: NodeBase > RectBase2D
|
Fields |
Type |
Use |
Default value |
Description |
|---|---|---|---|---|
|
anchorH |
senum |
Optional |
left |
Used when sizeMode is set to keepSize.
|
|
anchorV |
senum |
Optional |
top |
Used when sizeMode set to keepSize.
|
|
center |
svec2 |
Optional |
0 0 |
Sets the center of the 2D object referred to its top-left corner. If set to a value different from "0 0" the object position is given by position-center. This is useful to position an object with the center on a particular coordinate. |
|
children |
mstring |
Read only |
List of all nodes that have the same parent as listed in the parent field. Only first level children are listed here. Children of children are not in the list. |
|
|
invalidate |
sevent |
Event |
Causes the node to immediately redraw its graphical content. Works with both updateMode settings: dirty and direct. |
|
|
isOver |
sbool |
Optional |
Internally calculated |
Becomes true when the mouse is over the 2D component. |
|
joyInputEnable |
sbool |
Optional |
true |
Enables or disables automatic joypad interaction management. |
|
keyInputEnable |
sbool |
Optional |
true |
Enables or disables automatic keyboard interaction management. |
|
mouseInputEnable |
sbool |
Optional |
true |
Enables or disables automatic mouse interaction management. |
|
opacity |
sfloat |
Optional |
1 |
Changes node transparency in [0 1] range. (0 fully transparent, 1 fully opaque). Opacity is not supported when the 2D element is rendered into a Texture2D. |
|
order |
sint |
Optional |
100 |
The node z order. It defines the display order of different children. |
|
parent |
sstring |
Optional |
Can be set to another RectBase2D-derived class object name to create a hierarchy of elements. |
|
|
pixelInterpolation |
sbool |
Optional |
False for Text based nodes True for other nodes |
Enables subpixel interpolation for graphics that are scaled, or for which position is not pixel perfect. We advise keeping this parameter set to false for text nodes and static elements because disabling the pixel interpolation improves the graphic sharpness. We advise keeping this parameter set to true to improve the transition smoothness of animated elements. |
|
position |
svec2 |
Optional |
0 0 |
Sets the position of the node center to the given coordinates. If the node is a parent, the position refers to parent center position. |
|
propagateEvent |
sbool |
Optional |
false |
If set to true, the mouse events are propagated to underlying 2D nodes. |
|
renderToTexture2D |
sstring |
Optional |
Specifies Texture2D object name to render onto it. The Texture2D object name propagates to all RectBase2D-derived child elements on the hierarchy. |
|
|
scale |
svec2 |
Optional |
1 1 |
Proportionally scales the size of the node. This action propagates to node children. |
|
size |
svec2 |
Optional |
-1 -1 |
Defines the dimension of the 2D object. If value remains as "-1 -1" it is automatically set to image content size. Works only when a content file is set. |
|
sizeMode |
senum |
Optional |
stretchToGrid |
Enables you to set size mode: stretchToGrid or keepSize. This is useful for windowed applications. |
|
updateMode |
senum |
Optional |
dirty |
When set to dirty, the content is updated by the dirty update system. When set to direct, the content is updated when changed. |
|
visible |
sbool |
Optional |
false |
Shows or hides the node. |