A customizable horizontal compass UI for Unity games using UIToolkit. Displays player heading with cardinal directions and supports waypoint markers with distance tracking.
- Smooth horizontal compass bar with tick marks and cardinal directions.
- Real-time heading tracking based on camera rotation.
- Waypoint marker system with custom icons and colors.
- Distance display for each marker.
- Fully customizable via Inspector and USS stylesheets.
- Editor preview mode for testing without entering Play mode.
- Lightweight UI Toolkit based rendering.
- Download from the Releases page and import into your project.
- Ensure your project supports UI Toolkit (Unity 2021.2+).
Make sure you have a UI Document that the Compass can use.
- Add the Compass_Controller script to a GameObject.
- Add the UI Document reference.
Adjust the compass settings in the Inspector to match your game's needs.
| Setting | Description |
|---|---|
| UI Document | Reference to the UIDocument component (auto-detected if on same GameObject) |
| Compass Width | Width of the compass bar in pixels. Should match --compass-width in USS |
| Compass FOV | Field of view in degrees. Lower values zoom in, higher values show more of the world. Default: 150 |
| Editor Preview Heading | Simulates player heading in edit mode (0=North, 90=East, 180=South, 270=West) |
| Player Transform | Reference for distance calculations. Uses camera position if left empty |
| Editor Markers | List of waypoint markers to display |
Each marker in the Editor Markers list has:
| Field | Description |
|---|---|
| Target | The Transform to track in world space |
| Icon | Optional texture for the marker (uses default circle if empty) |
| Color | Tint color for the marker icon |
The compass appearance can be fully customized by editing UI/USS/Compass.uss.
// Get reference to the compass controller
Compass_Controller compass = GetComponent<Compass_Controller>();
// Add a marker with default settings
Compass_Marker marker = compass.add_marker(target_transform);
// Add a marker with custom icon and color
Compass_Marker custom_marker = compass.add_marker(
target_transform,
my_icon_texture,
Color.red
);// Remove a specific marker
compass.remove_marker(marker);
// Remove all markers
compass.clear_markers();MIT License - see LICENSE for details. Use freely for personal and commercial projects.

