Base components for building graphs/diagrams, similar to those found in visual scripting tools, using Unity's UIToolkit package.
Motivation: There are other solutions out there, but many are designed for legacy IMGUI editors, are editor-only, or too complex to get started with. Here, you'll find a simple and configurable diagram tool built with the new UIToolkit — just as easy as adding a new element in UI Builder — and ready for both editor and runtime use (since it's a UI element without editor dependencies). With this, I aim to address my personal criticisms of other solutions I've encountered.
To create a diagram, it's very simple:
- Download and add the
EZacafolder to your project underAssets. - Create a UI Document (UXML).
- Add the stylesheets
DiagramBaseStyle.uss,DiagramLight.uss, andDiagramDark.ussfromAssets\EZaca\Diagrams\Core\Styles. - (Optional) Add a ScrollView to your document, set it to Flex grow, and place the diagram inside it.
- Add a
DiagramElementto your document (you may want to set its width and height if you're using a ScrollView). - Add the
NodeElementitems you want (you can toggle theMovableoption). - Add
PortElementitems to the body of your nodes if you want to connect them. - Add a UIDocument to your scene (GameObject and component).
- Reference your UXML file there.
To connect nodes and allow the user to connect them:
- Add a new MonoBehaviour to your UIDocument GameObject.
- In
OnEnable, get a reference to the UIDocument. - Get a reference to your
DiagramElement.
E.g.:var diagram = UIDocument.rootVisualElement.Q<DiagramElement>() - Get references to the
PortElementinstances in the nodes. - Use
diagram.Connect(port1, port2, painter)to connect them. - Create a painter using
new BasicConnectionPaint(). - Allow the user to drag connections using:
diagram.AddDragConnectionService(). - Add further setup to the items, such as the
DragConnectionManipulatorreturned fromAddDragConnectionService, or customize theBasicConnectionPaint.
What is planned and may change?
DiagramDark.ussandDiagramLight.ussare currently separate files for easier maintenance. Merging all three USS files is under consideration.- While you can use the current setup via C# scripts, an
EnhancedDiagramcomponent is being considered, which would expose common configurations as properties. - A different connection of a straight line with smooth start and end is also being considered for
BasicConnectionPaint.





