–1 vote

Okay I am not new to programming and i just came from a different game engine.
i need to spawn/generate/instantiate an object into my scene using gdscript(the moment it runs).
After viewing the 3D environment, i know object MeshInstance should contain Mesh, transfrom, visibility and so on(basic understanding of objects)
So I tried to manually spawn a plane mesh and make the code similar to its parameters:

var plane = MeshInstance.new()
plane.mesh = PlaneMesh
plane.skeleton = "Root"

i received a logic error. it ran but i dont see my plane mesh also i cant seem to use

plane.transform.translation or

to set the position of my new plane mesh, even though translation should have been a node under transform.
Please help. How do i spawn an object and set its coordinates.

PS i was searching online but it talked about "Classtype" or "Add_child" or "set_name"
all of which i cant seem to use

in Engine by (264 points)
edited by

1 Answer

+1 vote

Transform doesn't have a translation property but an origin property. But MeshInstance inherits from Spatial which has the translation property as a shortcut for that, so it's:


# or for global translation

And you probably need to add the plane to the scene tree:


Maybe you're confused because Translation is under Transform in the Inspector but you can hover your mouse over to see the real underlined property name:

Spatial Inspect

Some properties are not shown in the Inspector like the transform property itself.

by (4,005 points)
edited by
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.