I'm trying to instantiate object(scene) and set it's spawn position at the spawn time. Here's the code I wrote:

func spawn_asteroid():
    var spawn_position: Vector3 = get_spawn_position()

    var asteroid_instance = asteroid_scene.instance()
    asteroid_instance.transform.origin = spawn_position


asteroid_scene is PackedScene, so get instance first, and then update it's position, and finally use add_child to append current scene's tree.

It seems fine to me, however when I run the game, the object was spawned at (0,0,0) and then move spawn_position.

I changed it's position before it appended to scene, but why it still (0,0,0) and right after move to the specified position?

In Unity, change object's location right after instancing works. In Godot Engine, is this approach invalid?

  • \$\begingroup\$ Temporarily fixed by hide mesh right after instantiated and used coroutine to wait very short time, and re-render. \$\endgroup\$ – modernator Nov 8 '19 at 7:53

I was able to reproduce this and filed an issue. Two things to note:

  1. There was a similar issue that was fixed in Godot 3.1, so ensure you're on the latest release.
  2. This only happened for me if I instanced a scene during _ready. If I instance a scene in _physics_process the object is immediately placed at its final destination.
| improve this answer | |
  • \$\begingroup\$ Well, I'm using Godot 3.1.1 so it seems they didn't fixed yet in latest release. \$\endgroup\$ – modernator Nov 8 '19 at 6:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.