Godot Version
4.5
Question
Look like some data of custom node is being lost after Build Project. After a rebuild, default constructor of the custom node is called, and only primitive data types (such as int, float, array) and Godot Variants are "copied". Everything else, like List<> is just initialized by the constructor. Below is example code snipped to test this behaviour.
So, I assumed that I probably needed to add custom serialization/deserializaion using _GetProperty, _Set, _Get overrides. Fine - now problem.
Now, my list is properly stored in scene file and reloaded (and also properly duplicated in editor).
What surprised me is that after Build Project, process of deserialization is not called at all!. So I ended up again with empty List<>. Only reloading the scene fills List<> data again. Is this intended or it's a bug? Is there anything I can do about it besides changing my List<> to Godot.Array<>?
I trying to avoid this because Godot.Array doesn't support BinarySearch with custom comparator (which is another story)...
using System.Collections.Generic;
using Godot;
[GlobalClass]
[Tool]
public partial class CustomNode : Node2D
{
private int testInt;
List<string> testList = new List<string>();
private int[] testArray = new int[5];
[ExportToolButton("Fill test data")]
public Callable TestButton => Callable.From(FillTestData);
[ExportToolButton("Print test data")]
public Callable PrintButton => Callable.From(PrintTestData);
public CustomNode()
{
GD.Print("CustomNode constructor called.");
}
private void FillTestData()
{
testInt = 42;
testList.Add("Alpha");
testList.Add("Beta");
testArray[0] = 1;
testArray[1] = 2;
GD.Print("Test data filled.");
}
public void PrintTestData()
{
GD.Print($"CustomNode is drawing. TestIn: {testInt}, TestList.Count: {testList.Count}, TestArray[0]: {testArray[0]}");
}
}