Godot Version
v4.4.stable.mono
Question
I’ve been writing a GltfDocumentExtension to change how things are imported. My issue is that trying to modify a exported array doesn’t appear to work.
When calling Array.Add() the array does resize but new entries aren’t saved.
Here is the node class I am using for this example:
[GlobalClass]
public partial class RoomWallRoot : Node3D
{
[Export] public Array<Node3D> ChildWalls = new();
/// <summary>
/// The child nodes (wall meshes) are hidden based on the dot product between the player camera and the normal set here
/// </summary>
[Export] public Vector3 WallRootNormal;
}
And here is the relevant line from the GltfDocumentExtension.
public override Error _ImportPost(GltfState state, Node root)
{
root.GetNodesOfTypeRecursively(out List<RoomWallRoot> roomWallRoots);
foreach (var roomWallRoot in roomWallRoots)
{
foreach (var child in roomWallRoot.GetChildren())
{
if (child is not Node3D node3D) { continue; }
node3D.Owner = root;
// Appears to work correctly
roomWallRoot.ChildWalls.Add(node3D);
}
foreach (var wall in roomWallRoot.ChildWalls)
{
// Appears to work here but doesn't actually serialize
GD.Print(wall == null ? "NULL" : wall);
}
}
return Error.Ok;
}
The WallRootNormal variable I can edit just fine and it serializes too. I do this in _ImportNode(). I tried setting the Array inside the _ImportNode() function but the issue was the same.
I can work around this by simply getting the children of the RoomWallRoot node in its ready function. But I am just wondering if there is a bug here with serializing array or something?