GraphNode Load/Save Position C#

Godot Version

v4.3.stable.mono.official

Question

I’m trying to save and load GraphNodes. I can set various attributes on the nodes but when I try to set the position using the basic pattern in Saving games — Godot Engine (stable) documentation in English the value doesn’t change.

That is…

var newObjectScene = GD.Load<PackedScene>(nodeData["Filename"].ToString());
var newObject = newObjectScene.Instantiate<Node>();
GetNode(nodeData["Parent"].ToString()).AddChild(newObject);

//this line
newObject.Set(Node2D.PropertyName.Position, new Vector2((float)nodeData["PosX"], (float)nodeData["PosY"]));

…doesn’t do anything. I’ve tried casting the object to GraphNode and I’ve also tried with GlobalPosition and PositionOffset but nothing changes the value.

I thought that maybe there is some trick to this as the nodes are controlled by the GraphEdit object?

Ok, so using “position_offset” worked or GraphNode.PropertyName.PositionOffset:

Set("position_offset", new Vector2((float)nodeData["PosX"], (float)nodeData["PosY"]));

Set(GraphNode.PropertyName.PositionOffset,  new Vector2((float)nodeData["PosX"], (float)nodeData["PosY"]));

Fairly simple but the lack of clear error messages made this problematic.

It’d be nice to have a “did you mean ‘position_offset’ instead of ‘PositionOffset’” error message using simple string matching against GraphNode.PropertyName properties. Or at least a “Property ‘PositionOffset’ not found” error message.