1
\$\begingroup\$

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
    spawned_asteroids.append(asteroid_instance)

    add_child(asteroid_instance)

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?

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

1 Answer 1

1
\$\begingroup\$

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.
\$\endgroup\$
1
  • \$\begingroup\$ Well, I'm using Godot 3.1.1 so it seems they didn't fixed yet in latest release. \$\endgroup\$ Commented Nov 8, 2019 at 6:32

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.