|
VR-Engage
2.3
|
Purpose: This example demonstrates how to extend DtEntityOverlayComponent to enrich entity overlays with per-entity health data. The custom component tracks entities in the player-station overlay pipeline and publishes a health value that downstream QML or overlay logic can render as a health bar or status label.
Observable Behavior: When the example is loaded in VR-Engage with the example simulation model set, entity overlays include additional health information for tracked entities. Human entities use the stateProperties.OverallHealth attribute, while other entities fall back to their damageState value and convert it to a percentage-style health estimate.
Prerequisites: Familiarity with the VR-Engage Player Station framework, entity overlay components, and the role/component registration pattern for frontend plugins. A working understanding of DtEntityOverlayComponent is useful when adapting the example to a custom UI. Use the example simulation model set and role files included with this example for the intended runtime setup.
Related Examples: See QML HUD for an example of QML-driven overlay data binding and Entity Detection for another frontend-plus-backend overlay pattern.
This example demonstrates the minimal pattern for custom entity overlays:
DtEntityOverlayComponent and overrides the data population hook.stateProperties.OverallHealth and non-humanoid entities that represent health as damageState.The implementation is intentionally small. It does not introduce new network messages or backend simulation logic; it adds data to the existing overlay pipeline so that the UI layer can decide how to render it.
The plugin entry point registers the custom overlay component with VR-Engage's component factory:
The component type string DtEntityHealthBarOverlayType is defined in the header and must match the type name used when the component is instantiated from role configuration.
The example defines a small component subclass that adds only the health-data behavior required for overlays:
This keeps the example focused on the overlay contract rather than adding unrelated player-station logic.
The component adds the attributes it needs to the overlay pipeline during initialization:
This ensures the component keeps the required values synchronized for each tracked entity. The overlay base class handles the broader entity tracking and projection steps; this example only requests the specific attributes it needs.
The override method adds a health entry to the entity overlay payload:
This is the core behavior: the base class computes the entity's screen-space position, and this override adds a numeric health value into EntityOverlayInfo::extraData. The actual rendering of the bar or label is up to the QML or overlay consumer that reads the data model.
This example is a frontend plugin only. It does not add a simulation-side actuator or custom message type. Instead, it depends on the existing overlay pipeline defined by DtEntityOverlayComponent in include/commonRoleLibraries/vreCommonComponents/entityOverlayComponent.h:
DtEntityOverlayComponent tracks entities and projects their positions to screen space.EntityOverlayInfo carries the overlay state and per-entity metadata.extraData exposes custom properties such as health for QML or other renderers.The plugin therefore behaves as a data-provider for the broader overlay framework, rather than as a standalone renderer.
Build the example target from the examples solution:
Install the plugin for the current VR-Engage build:
The CMake target installs the plugin to the VR-Engage plugin directory:
<VR-Engage-Install-Dir>\plugins64\vrEngage\release\exampleEntityHealthBars.dllPlease run this example with the provided SMS which is entityHealthBar.sms. The example role file is located at:
data/data/simulationModelSets/examples/entityHealthBar/roles/militaryHumanWithOverlays.luaThe asset also references the example QML overlay file at data/UI/examples/exampleEntityOverlay.qml.
Use the example model set when launching VR-Engage:
The exact SMS name present in the example data directory is the example model set for this scenario; it contains a human role that uses the overlay component. This is the intended setup for verifying the example in the same way the example role is authored.
The example role adds the new component in the role definition by setting the component type to DtEntityHealthBarOverlay and pointing to the QML file used by the overlay:
This entry is what makes the player station instantiate the DtEntityHealthBarOverlay component for the role. The qmlFilename property tells the overlay framework which QML item to populate, while qmlDataItemObjectName identifies the target object in that file. The example therefore combines the C++ overlay component with a role configuration that attaches it to a human entity.
entityHealthBars plugin.entityHealthBar.militaryHumanWithOverlays human role.Expected Behavior:
health from stateProperties.OverallHealth.health from damageState values.additionalHeightAboveEntity is set for humanoid entities so the overlay is offset above the entity.No health values appear:
stateProperties.OverallHealth or a valid damageState attribute.Overlay not displayed:
DtEntityHealthBarOverlay component.health field from EntityOverlayInfo::extraData.