create_widget
Creates a runtime UUserWidget instance in PIE/editor and, when a local PlayerController exists, optionally adds it to the viewport.
Instructions
Create a runtime UUserWidget instance of a concrete UserWidget class in a running PIE world (the default while PIE runs) or the editor world, owned by that world's first local PlayerController when there is one, and optionally AddToViewport it. Nothing is saved, and an unreferenced widget is garbage-collected. In the editor world add_to_viewport never adds (no PlayerController): read added_to_viewport. A taken name gets a unique variant, reported in widget_name; a class that does not load, is abstract or is not a UserWidget is an error. To change the asset use add_widget_to_blueprint; remove_widget searches the same worlds.
Returns: { widget_name: string, widget_class_path: string, widget_class_name: string, target_world: string, added_to_viewport: bool, add_to_viewport_note?: string, widget_valid: bool, world_name: string|null, world_package: string|null, world_type: string|null, net_mode: string|null, pie_instance: number }
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| widget_name | Yes | Name to assign to the created widget instance (a name another widget already has gets a unique variant, which widget_name in the response reports) | |
| target_world | No | Optional: "editor" | "pie" | "server" (the PIE world with authority) | "client" | "pie:N" | "game" (alias of "pie"). Defaults to "pie" when a Play-In-Editor session is running, else "editor". IMPORTANT: "editor" NEVER has a PlayerController, because GEditor's world is not a game world, so add_to_viewport can never really add there -- that is reported honestly (added_to_viewport stays false), never simulated. "pie" resolves the running PIE world and its first local PlayerController, so add_to_viewport there performs a REAL AddToViewport(). | |
| add_to_viewport | No | If true, AddToViewport the widget (optional, default false). It only ever really adds when the target world has a local PlayerController -- check added_to_viewport in the response, and see target_world for when that is possible at all. | |
| widget_class_path | Yes | Full path to widget class, e.g. '/Game/UI/MyWidget.MyWidget_C' |