Using Unity’s Graph View

Node Position, Code/Editor Window Reload

James Lafritz
2 min readJun 4, 2022

EDIT: The base for this code is heavily based on The KiwiCoder’s Behavior Tree.

The main difference between the 2 is the way the Style Sheet is linked and the behavior of the node inputs. The Project Files can be Found on GitHub at.

Node Position

One of the problems right now is if I move the Node around when I go back to edit the graph the nodes appear right on top of each other. To fix this I need to remember the position in the graph the node was last at.

The Node needs a Vector2 for the position it is in in the graph.

Node Graph Position added to the Node

In the Behavior Tree Node View I need to override the Nodes Set Position. I set the Node’s Node Graph Position to be the X Min and Y Min of the rectangle.

Override Set Position of Behavior Tree Node View

Then I change the Style of the Node View Left to be the Node’s x position and the Top to be the Node’s y position.

And Now The Position is remembered.

Fixing the Selection Change On Code Reload

Now the other problem is every time I make a change to the Code Unity Reloads and I get a new Editor Window. The Window forgets what was selected and I have to select something in Unity then re-select my behavior tree. To fix this in the Behavior Tree Editor when I Create the GUI I just add a call to the On Selection Change at the end.

Call To On Selection Change Added

Now when ever the Editor Window gets Reloaded it will run the On Selection Change.

Editor Window Reloading



James Lafritz

Excited about changing my hobby into a new carer with GameDevHQ course.