0 votes

I am using godot 3.1.1 stable win64. I wanted to add a mesh to a new MeshInstance node, I made using GDScript. So I used

var plane = MeshInstance.new()
plane.mesh = PlaneMesh
add_child(plane)

This did not work. So I manually added a new MeshInstance called MeshIn2 with a plane added in, using the 3D environment tab. After that, i open my script and I did

var plane = MeshInstance.new()
plane.mesh = $MeshIn2.mesh
add_child(plane)

Here is where it gets weird. Running the code I receive no error messages and my new MeshInstance is still invisible because there was no mesh, but my MeshIn2 which was clearly there in my scene until I ran the code turned invisible as well. Being skeptical, I removed

  plane.mesh = $MeshIn2.mesh

and ran the code, my MeshIn2 became visible again in my scene. I was confused so i tinkered around wondering what happens if change the mesh of my MeshIn2 so i removed all other stuff from my script and wrote

$MeshIn2.mesh = CubeMesh

The result was MeshIn2 became invisible. Please help need.

in Engine by (264 points)

1 Answer

+2 votes
Best answer

PlaneMesh is just a class. You need to instance it:

var plane = MeshInstance.new()
plane.mesh = PlaneMesh.new()
add_child(plane)
by (4,101 points)
selected by

Thank you. It works now :)

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.