XML style language for creating uGUI GameObject hierachies in Unity.
This library was created since I found Unity's uxml & uss system to be to cumbersome and it's animation system to rigid. This allows for text files to be created manually or by LLM as I needed a solution where GUI and GUI assets could be loaded during runtime from on external source. However the GameObject uGUI system is still used allowing the familiar development patterns developed over the years without retraining designers.
A lot of this code was AI generated with expert guidance. It is however sloppy and in active development. Concider this a prototype. A better solution may be to use ScriptableObjects/prefabs for templating or parse uxml/uidocs to uGUI and uss to animation components.
- Automatic uGUI opimization practices.
- Custom animation system for moving UI GameObjects.
- Custom resource system for loading images and text from external sources.
- Load/edit uGUI with XML style markup files.
- Export existing canvas hierarchies to UGUIML files.
- Getting Started
- File Structure
- Core Components
- Layout System
- Event System
- Canvas System
- Styling and Appearance
- Animation System
- Best Practices
- Examples
- Troubleshooting
- Import the UGUIML package into your Unity project
- Add the
UGUIML
component to a GameObject in your scene - Set the
xmlFileName
property to your.uguiml
file name - Place your
.uguiml
files in theAssets/UGUIML/Examples/
folder
Create a new file called MyFirstUI.uguiml
:
<?xml version="1.0" encoding="UTF-8"?>
<UGUIML>
<Panel name="MainPanel"
position="0,0"
size="400,300"
backgroundColor="#2C3E50">
<Text name="WelcomeText"
text="Welcome to UGUIML!"
position="0,50"
size="350,40"
fontSize="24"
color="#FFFFFF"
alignment="center" />
<Button name="ClickMeBtn"
text="Click Me!"
position="0,-50"
size="150,40"
backgroundColor="#3498DB"
textColor="#FFFFFF"
command="HandleClick" />
</Panel>
</UGUIML>
Every UGUIML file must start with the XML declaration:
<?xml version="1.0" encoding="UTF-8"?>
The root element must be <UGUIML>
:
<UGUIML>
<!-- Your UI components go here -->
</UGUIML>
Components can be nested to create parent-child relationships:
<Panel name="Parent">
<Panel name="Child">
<Text name="Grandchild" />
</Panel>
</Panel>
Creates a UI Panel component for grouping and layout.
Attributes:
name
(required): Unique identifierposition
: X,Y position relative to parentsize
: Width,Height dimensionsbackgroundColor
: Hex color code (#RRGGBB)anchorMin
: Minimum anchor point (X,Y)anchorMax
: Maximum anchor point (X,Y)animationSpeed
: Animation duration multiplier
Example:
<Panel name="MainContainer"
position="0,0"
size="800,600"
backgroundColor="#34495E"
anchorMin="0.5,0.5"
anchorMax="0.5,0.5" />
Displays text content.
Attributes:
name
(required): Unique identifiertext
: Text content to displayposition
: X,Y positionsize
: Width,Height dimensionsfontSize
: Text size in pointscolor
: Text color (#RRGGBB)alignment
: Text alignment (left, center, right)
Example:
<Text name="Title"
text="My Application"
position="0,100"
size="400,50"
fontSize="28"
color="#FFFFFF"
alignment="center" />
Interactive button component.
Attributes:
name
(required): Unique identifiertext
: Button labelposition
: X,Y positionsize
: Width,Height dimensionsbackgroundColor
: Button background colortextColor
: Text colorfontSize
: Text sizecommand
: Event command to execute on click
Example:
<Button name="SaveBtn"
text="Save"
position="100,0"
size="120,40"
backgroundColor="#27AE60"
textColor="#FFFFFF"
fontSize="16"
command="SaveData" />
Text input component.
Attributes:
name
(required): Unique identifierplaceholder
: Placeholder texttext
: Initial text valueposition
: X,Y positionsize
: Width,Height dimensionsbackgroundColor
: Background colortextColor
: Text colorfontSize
: Text sizecontentType
: Input type (standard, password, email, etc.)
Example:
<InputField name="UsernameField"
placeholder="Enter username..."
position="0,50"
size="300,35"
backgroundColor="#FFFFFF"
textColor="#2C3E50"
fontSize="14" />
Checkbox/toggle component.
Attributes:
name
(required): Unique identifiertext
: Label textposition
: X,Y positionsize
: Width,Height dimensionsisOn
: Initial state (true/false)
Example:
<Toggle name="EnableSoundToggle"
text="Enable Sound Effects"
position="0,0"
size="200,25"
isOn="true" />
Selection dropdown component.
Attributes:
name
(required): Unique identifierposition
: X,Y positionsize
: Width,Height dimensionsbackgroundColor
: Background colortextColor
: Text colorfontSize
: Text sizeoptions
: Comma-separated list of optionsvalue
: Selected index (0-based)
Example:
<Dropdown name="QualityDropdown"
position="0,0"
size="200,35"
backgroundColor="#FFFFFF"
options="Low,Medium,High,Ultra"
value="2"
fontSize="14"
textColor="#2C3E50" />
Progress indicator component.
Attributes:
name
(required): Unique identifierposition
: X,Y positionsize
: Width,Height dimensionsminValue
: Minimum valuemaxValue
: Maximum valuevalue
: Current valuebackgroundColor
: Background colorfillColor
: Fill color
Example:
<ProgressBar name="LoadingBar"
position="0,0"
size="300,20"
minValue="0"
maxValue="100"
value="75"
backgroundColor="#ECF0F1"
fillColor="#3498DB" />
Value slider component.
Attributes:
name
(required): Unique identifierposition
: X,Y positionsize
: Width,Height dimensionsminValue
: Minimum valuemaxValue
: Maximum valuevalue
: Current valuebackgroundColor
: Background colorfillColor
: Fill color
Example:
<Slider name="VolumeSlider"
position="0,0"
size="200,20"
minValue="0"
maxValue="100"
value="50"
backgroundColor="#95A5A6"
fillColor="#3498DB" />
UGUIML supports multiple positioning methods:
<Panel position="100,50" size="200,100" />
<Panel anchorMin="0,0" anchorMax="1,1" />
For backward compatibility, you can also use:
<Panel anchoredPosition="0,0" width="200" height="100" />
<Panel name="HorizontalContainer">
<Button position="-100,0" size="80,40" />
<Button position="0,0" size="80,40" />
<Button position="100,0" size="80,40" />
</Panel>
<Panel name="VerticalContainer">
<Button position="0,60" size="200,40" />
<Button position="0,0" size="200,40" />
<Button position="0,-60" size="200,40" />
</Panel>
<Panel name="GridContainer">
<Button position="-50,25" size="40,40" />
<Button position="0,25" size="40,40" />
<Button position="50,25" size="40,40" />
<Button position="-50,-25" size="40,40" />
<Button position="0,-25" size="40,40" />
<Button position="50,-25" size="40,40" />
</Panel>
UGUIML provides a comprehensive event system for handling user interactions.
The simplest way to handle events is using the command
attribute:
<Button command="SaveGame" />
<Button command="LoadGame|level1" />
<Button command="SetVolume|0.8" />
Create a script that implements event handlers:
public class UIEventHandler : MonoBehaviour
{
public void SaveGame()
{
// Handle save game
}
public void LoadGame(string level)
{
// Handle load game with parameter
}
public void SetVolume(float volume)
{
// Handle volume change
}
}
onClick
: Triggered when button is clicked
onValueChanged
: Triggered when text changesonEndEdit
: Triggered when editing endsonSubmit
: Triggered when Enter is pressed
onValueChanged
: Triggered when toggle state changes
onValueChanged
: Triggered when selection changes
onValueChanged
: Triggered when value changes
Events can include parameters separated by pipe (|
) characters:
<Button command="PlaySound|buttonClick|0.5" />
<Button command="ChangeScene|MainMenu" />
<Button command="SpawnEnemy|Goblin|10,20" />
UGUIML supports nested canvas creation for complex UI hierarchies.
<Canvas name="MainCanvas"
renderMode="ScreenSpaceOverlay"
sortingOrder="0"
pixelPerfect="true"
referenceResolution="1920,1080"
scaleMode="ScaleWithScreenSize"
matchWidthOrHeight="0.5">
<!-- Canvas content -->
</Canvas>
renderMode
: Rendering mode (ScreenSpaceOverlay, ScreenSpaceCamera, WorldSpace)sortingOrder
: Sorting order for multiple canvasespixelPerfect
: Enable pixel perfect renderingreferenceResolution
: Reference screen resolution (Width,Height)scaleMode
: UI scale modematchWidthOrHeight
: Match ratio (0=width, 1=height, 0.5=balanced)
<UGUIML>
<Panel name="MainUI">
<!-- Main UI content -->
<Canvas name="ModalOverlay" sortingOrder="10">
<Panel name="ModalDialog" backgroundColor="#000000AA">
<Text text="Are you sure?" />
<Button text="Yes" command="ConfirmAction" />
<Button text="No" command="CancelAction" />
</Panel>
</Canvas>
</Panel>
</UGUIML>
Colors are specified using hex codes:
<Panel backgroundColor="#2C3E50" /> <!-- Dark blue-gray -->
<Text color="#FFFFFF" /> <!-- White -->
<Button backgroundColor="#E74C3C" /> <!-- Red -->
<!-- Material Design Colors -->
<Panel backgroundColor="#2196F3" /> <!-- Blue -->
<Panel backgroundColor="#4CAF50" /> <!-- Green -->
<Panel backgroundColor="#FF9800" /> <!-- Orange -->
<Panel backgroundColor="#9C27B0" /> <!-- Purple -->
<Panel backgroundColor="#F44336" /> <!-- Red -->
<Panel backgroundColor="#607D8B" /> <!-- Blue Gray -->
<Text fontSize="12" /> <!-- Small -->
<Text fontSize="16" /> <!-- Normal -->
<Text fontSize="20" /> <!-- Large -->
<Text fontSize="24" /> <!-- Extra Large -->
<Text fontSize="32" /> <!-- Heading -->
<Text alignment="left" />
<Text alignment="center" />
<Text alignment="right" />
UGUIML includes built-in animation support for smooth UI transitions.
Control animation timing with the animationSpeed
attribute:
<Panel animationSpeed="1.0" /> <!-- Normal speed -->
<Panel animationSpeed="0.5" /> <!-- Slower -->
<Panel animationSpeed="2.0" /> <!-- Faster -->
Most components support animation:
<Panel name="AnimatedPanel"
position="0,0"
size="300,200"
backgroundColor="#3498DB"
animationSpeed="1.5">
<Text name="FadeInText"
text="Animated Text"
animationSpeed="2.0" />
</Panel>
- Use descriptive file names:
MainMenu.uguiml
,InventoryPanel.uguiml
- Group related UI files in folders
- Keep files focused on single UI screens or components
- Use PascalCase for component names:
MainPanel
,SaveButton
- Include component type in names:
UsernameInputField
,VolumeSlider
- Use descriptive names:
PlayerHealthBar
instead ofBar1
- Design for multiple screen resolutions
- Use relative positioning when possible
- Maintain consistent spacing and alignment
- Group related elements in panels
- Minimize deeply nested hierarchies
- Use appropriate canvas render modes
- Avoid excessive animation speeds
- Reuse common UI patterns
<!-- Good: Well-organized structure -->
<UGUIML>
<!-- Header Section -->
<Panel name="Header">
<!-- Header content -->
</Panel>
<!-- Main Content -->
<Panel name="MainContent">
<!-- Main content -->
</Panel>
<!-- Footer Section -->
<Panel name="Footer">
<!-- Footer content -->
</Panel>
</UGUIML>
<?xml version="1.0" encoding="UTF-8"?>
<UGUIML>
<Panel name="LoginPanel"
position="0,0"
size="400,500"
backgroundColor="#34495E"
anchorMin="0.5,0.5"
anchorMax="0.5,0.5">
<Text name="LoginTitle"
text="Login"
position="0,150"
size="300,50"
fontSize="32"
color="#FFFFFF"
alignment="center" />
<InputField name="UsernameField"
placeholder="Username"
position="0,50"
size="300,40"
backgroundColor="#FFFFFF"
textColor="#2C3E50"
fontSize="16" />
<InputField name="PasswordField"
placeholder="Password"
position="0,0"
size="300,40"
backgroundColor="#FFFFFF"
textColor="#2C3E50"
fontSize="16"
contentType="password" />
<Button name="LoginButton"
text="Login"
position="0,-50"
size="150,40"
backgroundColor="#3498DB"
textColor="#FFFFFF"
fontSize="16"
command="AttemptLogin" />
<Button name="RegisterButton"
text="Register"
position="0,-100"
size="150,40"
backgroundColor="#95A5A6"
textColor="#FFFFFF"
fontSize="16"
command="ShowRegister" />
</Panel>
</UGUIML>
<?xml version="1.0" encoding="UTF-8"?>
<UGUIML>
<Panel name="SettingsPanel"
position="0,0"
size="600,700"
backgroundColor="#2C3E50">
<Text name="SettingsTitle"
text="Settings"
position="0,300"
size="500,50"
fontSize="28"
color="#FFFFFF"
alignment="center" />
<!-- Audio Settings -->
<Panel name="AudioSection" position="0,150" size="550,120" backgroundColor="#34495E">
<Text name="AudioLabel" text="Audio Settings" position="0,40" size="500,30" fontSize="18" color="#FFFFFF" alignment="center" />
<Text name="VolumeLabel" text="Master Volume:" position="-150,0" size="120,25" fontSize="14" color="#FFFFFF" alignment="left" />
<Slider name="VolumeSlider" position="50,0" size="200,25" minValue="0" maxValue="100" value="75" backgroundColor="#95A5A6" fillColor="#3498DB" />
<Toggle name="MuteToggle" text="Mute All Sounds" position="0,-25" size="200,25" isOn="false" />
</Panel>
<!-- Graphics Settings -->
<Panel name="GraphicsSection" position="0,0" size="550,120" backgroundColor="#34495E">
<Text name="GraphicsLabel" text="Graphics Settings" position="0,40" size="500,30" fontSize="18" color="#FFFFFF" alignment="center" />
<Text name="QualityLabel" text="Quality:" position="-150,0" size="80,25" fontSize="14" color="#FFFFFF" alignment="left" />
<Dropdown name="QualityDropdown" position="50,0" size="150,30" backgroundColor="#FFFFFF" textColor="#2C3E50" fontSize="14" options="Low,Medium,High,Ultra" value="2" />
<Toggle name="FullscreenToggle" text="Fullscreen" position="0,-25" size="150,25" isOn="true" />
</Panel>
<!-- Control Buttons -->
<Panel name="ButtonSection" position="0,-200" size="550,80" backgroundColor="#34495E">
<Button name="ApplyButton" text="Apply" position="-75,0" size="100,40" backgroundColor="#27AE60" textColor="#FFFFFF" fontSize="16" command="ApplySettings" />
<Button name="ResetButton" text="Reset" position="75,0" size="100,40" backgroundColor="#E67E22" textColor="#FFFFFF" fontSize="16" command="ResetSettings" />
<Button name="BackButton" text="Back" position="0,-40" size="100,40" backgroundColor="#95A5A6" textColor="#FFFFFF" fontSize="16" command="BackToMainMenu" />
</Panel>
</Panel>
</UGUIML>
<?xml version="1.0" encoding="UTF-8"?>
<UGUIML>
<Panel name="InventoryPanel"
position="0,0"
size="800,600"
backgroundColor="#2C3E50">
<Text name="InventoryTitle"
text="Inventory"
position="0,250"
size="700,50"
fontSize="24"
color="#FFFFFF"
alignment="center" />
<!-- Inventory Grid -->
<Panel name="InventoryGrid" position="0,50" size="600,400" backgroundColor="#34495E">
<!-- Row 1 -->
<Button name="Slot1" position="-225,150" size="60,60" backgroundColor="#95A5A6" command="SelectItem|1" />
<Button name="Slot2" position="-150,150" size="60,60" backgroundColor="#95A5A6" command="SelectItem|2" />
<Button name="Slot3" position="-75,150" size="60,60" backgroundColor="#95A5A6" command="SelectItem|3" />
<Button name="Slot4" position="0,150" size="60,60" backgroundColor="#95A5A6" command="SelectItem|4" />
<Button name="Slot5" position="75,150" size="60,60" backgroundColor="#95A5A6" command="SelectItem|5" />
<Button name="Slot6" position="150,150" size="60,60" backgroundColor="#95A5A6" command="SelectItem|6" />
<Button name="Slot7" position="225,150" size="60,60" backgroundColor="#95A5A6" command="SelectItem|7" />
<!-- Row 2 -->
<Button name="Slot8" position="-225,75" size="60,60" backgroundColor="#95A5A6" command="SelectItem|8" />
<Button name="Slot9" position="-150,75" size="60,60" backgroundColor="#95A5A6" command="SelectItem|9" />
<Button name="Slot10" position="-75,75" size="60,60" backgroundColor="#95A5A6" command="SelectItem|10" />
<Button name="Slot11" position="0,75" size="60,60" backgroundColor="#95A5A6" command="SelectItem|11" />
<Button name="Slot12" position="75,75" size="60,60" backgroundColor="#95A5A6" command="SelectItem|12" />
<Button name="Slot13" position="150,75" size="60,60" backgroundColor="#95A5A6" command="SelectItem|13" />
<Button name="Slot14" position="225,75" size="60,60" backgroundColor="#95A5A6" command="SelectItem|14" />
<!-- Additional rows... -->
</Panel>
<!-- Item Details Panel -->
<Panel name="ItemDetails" position="0,-150" size="700,100" backgroundColor="#34495E">
<Text name="ItemName" text="Select an item" position="0,25" size="600,30" fontSize="18" color="#FFFFFF" alignment="center" />
<Text name="ItemDescription" text="Item details will appear here" position="0,-10" size="600,25" fontSize="14" color="#BDC3C7" alignment="center" />
<Button name="UseButton" text="Use" position="-75,-40" size="80,30" backgroundColor="#27AE60" textColor="#FFFFFF" fontSize="14" command="UseItem" />
<Button name="DropButton" text="Drop" position="75,-40" size="80,30" backgroundColor="#E74C3C" textColor="#FFFFFF" fontSize="14" command="DropItem" />
</Panel>
</Panel>
</UGUIML>
Problem: "Root element is missing" or XML parsing fails Solution:
- Ensure file starts with
<?xml version="1.0" encoding="UTF-8"?>
- Check that root element is
<UGUIML>
- Verify all tags are properly closed
- Escape special characters in text content
Problem: UI components don't show up in game Solution:
- Check component name is unique
- Verify position and size attributes
- Ensure parent panel is large enough
- Check anchor settings
Problem: Button clicks or other events don't work Solution:
- Verify command name matches method name
- Ensure UIEventHandler script is attached to appropriate GameObject
- Check method signature matches parameter types
- Verify method is public
Problem: Components overlapping or positioned incorrectly Solution:
- Check Canvas Scaler settings (should be 1920x1080 reference)
- Verify anchor points are set correctly
- Ensure position values are appropriate for screen size
- Use appropriate canvas render mode
Problem: UI is slow or laggy Solution:
- Reduce animation speeds
- Minimize nested canvas hierarchies
- Use appropriate canvas render modes
- Optimize complex layouts
- Use Unity Console: Check for error messages and warnings
- Verify File Path: Ensure
.uguiml
files are in correct directory - Test Incrementally: Start with simple UI and add complexity gradually
- Check Component Names: Ensure all names are unique within the hierarchy
- Validate XML: Use XML validator to check syntax
- File doesn't contain proper
<UGUIML>
root element - Check file encoding and XML declaration
- Duplicate component names in hierarchy
- Use unique names for all components
- Invalid hex color format
- Use format:
#RRGGBB
(e.g.,#FF0000
for red)
- Event handler method doesn't exist
- Check method name spelling and public access