I feel like having a basic knowledge gap, which causes recurring issues. In some cases doing stuff by editor and reproduce it by code is not that easy because you dont know what editor is doing for you.
Like instantiating a node by drag and drop into the scene tree ontop of another node and makes it a child of it. So from now on the child node stick on its parents position and gets it updated automatically in case of animations and stuff.
Now if you want to reproduce it by code:
var child = load("res://child_node.tscn").instantiate()
parent_node.add_child(child)
That not behave same as in the editor. I have hard times even get its position some times, especially if it comes to animations and updating the current position. Why is that the case, what is happening under the hood of the editor.
Most of the things that editor does can be replicated by code. The thing is that those actions that you described takes different steps.
For example, just instancing through editor using the chain button steps are pretty similar to what you did:
var child = load("res://child_node.tscn").instantiate()
parent_node.add_child(child)
This is the previous code + getting the mouse position. Since it was a drag&drop action and editor is built with control nodes, it has a function to know where the node was dropped, and the editor solves the position between the position in the screen and the viewport.
This is a different task What are you trying to do?
Inside Editor: Create a BoneAttachment3D and choose specific bone. Now attach any node as child node to it. The result is, the attached node moves with the BoneAttachment3D Node, even with animations.
Inside Code: If recreating the same by code, attached nodes, wont move with the parent node (BoneAttachment3D).
I’m facing basically this issue that you described:
I create a BoneAttachement3D in the editor = all good
I create a BoneAttachement3D in the code = it seems to be fine, but when I check its GlobalPosition, it’s wrong (hence, anything I make child of it it’s displayed in the wrong position).
BoneAttachment3D boneAttachment = new BoneAttachment3D();
boneAttachment.BoneIdx = boneId;
skeleton.AddChild(boneAttachment);
I tried using the Ready event (to make sure when I check the GlobalPosition it’s all loaded) but it’s the same.
Any idea what the editor is actually doing? I’m planning to report this as a bug, as this is the 3rd forum I’m asking and nobody knows :-/