#Possible bug in index assignment?

1 messages · Page 1 of 1 (latest)

round zenith
#

It appears that Godot doesn't appear to be sorting indexes correctly in-editor. You see, I'm trying to make a PaperRenderer Node3D that renders its Polygon2D node children into 3D meshes. An important part for this to work, is to be able to tell which Polygon2D node is on top of the other, and order the 3D meshes accordingly.

Now, I'm trying to add functionality to allow the automatic deletion and addition of a mesh when a Polygon2D is removed/added as a child of PaperRenderer, and for the latter, I'm gonna need to be able to automatically re-sort all of my 3D meshes' positions when this happens. Now, as for my problem. My RightArm Polygon2D node is placed at the top of the other Polygon2Ds. It should have an index of 0. When I delete it, and undo its deletion, it correctly spawns back, but with the wrong index. It instead just shoves it to the bottom of the index, alongside its generated mesh. When I reload the scene, the mesh is fortunately in its proper index, but still, I don't want people to have to do that every time. Plus, that doesn't help if someone wants to also dynamically throw a Polygon2D in a PaperRenderer in runtime.

I put together print(child.name + ": " + str(child.get_index())) in the for child in get_children(): loop, and here's what it outputs:

Body: 1
LeftLeg: 2
Head: 3
Chin: 4
LeftArm: 5
@MeshInstance3D@31153: 6
@MeshInstance3D@31154: 7
@MeshInstance3D@31155: 8
@MeshInstance3D@31156: 9
@MeshInstance3D@31157: 10
@MeshInstance3D@31158: 11
RightArm: 12 
@MeshInstance3D@36758: 13```

Now, I'm admittedly not sure what to do here. I can't seem to find any other way to properly sort these nodes depending on how they're sorted in the scene. I did try using `node.is_greater_than()` to attempt to sort it, but that didn't help at all, as I'm pretty sure that also relies on the same index to check for that.

Images for reference. Before deletion + addition and after deletion + addition.
round zenith
#

I guess a possible workaround would be somehow "refreshing" the indexes under PaperRenderer, but I'm not quite sure how to accomplish that.

round zenith
#

Looking into it, getting the tree instead seems to return them all in proper order actually. I'll come back and maybe mark this as solved if I am able to successfully use this to my advantage.