+2 votes

I thought I had this figured out but somehow I can't seem to get it to work as I would expect.

I have a Position3D node where I want to instance a scene (bullet) at

I create a reference to the scene like this: const BULLET = preload("res://Bullet.tscn")

I then instance the scene like this: var bullet_instance = BULLET.instance()

Finally I position the instance like this: bullet_instance.global_transform = global_transform

This code is running on the Position3D node where I want to create the bullets. The code runs, but it doesn't create any bullets that I can tell. When I look in the remote scene tree at run time no new nodes are being created.

in Engine by (30 points)

1 Answer

+3 votes
Best answer

You need to add the bullet instance as a child of some node, in order to add it to the tree and to render it to the screen. Use the Node.add_child method on the parent node.
Also, I would recommend against adding it to the Position3D, as translating this node afterwards might create some strange effects.

by (72 points)
selected by

That's got it. Thank you.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.