Godot Version
v4.2.2.stable.official [15073afe3]
Question
I was experimenting with instantiating scenes through code (object_scene.instantiate()) and placing them, and found that the position for the child scene is (0, 0) for the first physics frame. Here is console output:
(parent) OBJ INSTANTIATED
(child) OBJ READY FUNC TRIGGERED. OBJ POS: (0, 0)
(parent) OBJ ADDED TO PARENT SCENE
(parent) OBJ POSITION SET: (152, 40)
(physics_process 0) OBJ POS: (0, 0)
(physics_process 1) OBJ POS: (152, 40)
(physics_process 2) OBJ POS: (152, 40)
(physics_process 3) OBJ POS: (152, 40)
(physics_process 4) OBJ POS: (152, 40)
From this I could see that the objected is created and set to (152, 40), but it is not acknowledged by the physics_process until the second frame. On the first frame it thinks the position is (0, 0).
In case it was a timing issue, I attempted to wait a frame after setting the position with “await get_tree().process_frame” and also tried a deferred call “obj.set_deferred(“global_position”, Vector2(152, 40))”, but both had the same result. It appears that the first call of _physics_process always thinks the position is (0, 0).
Is this a normal behavior, or a bug? Is there a good fix or workaround? I am currently planning to simply ignore the first physics frame for any instantiated objects that use position in their physics, but I don’t know if this is an issue that could leak into subsequent frames in a more complex project.