godotengine / godot-docs

Godot Engine official documentation
https://docs.godotengine.org
Other
3.78k stars 3.07k forks source link

Probable missing line of code in example code, ArrayMesh documentation #9675

Open AlphaLuceatLaetis opened 1 month ago

AlphaLuceatLaetis commented 1 month ago

Godot version: Godot 4.2.2, Documentation referred to stable(4.2)

Issue description: Following the ArrayMesh tutorial and explanation, in the first "full" code example, the last line explains how to create the mesh with all the data we settled up:

# Create mesh surface from mesh array.
# No blendshapes, lods, or compression used.
mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, surface_array)

"mesh" isn't declared anywhere in the code example, making it hard for a new user to identify where to find the function and what "mesh" actually is. I'd suggest adding the declaration for "mesh", making it straightforward what it is. I guess the solution should be to add "var mesh=ArrayMesh.new()", making the example code clearer.

URL to the documentation page: https://docs.godotengine.org/en/stable/tutorials/3d/procedural_geometry/arraymesh.html

AThousandShips commented 1 month ago

You've missed that this script is attached to a MeshInstance3D, the mesh is a property

You missed this part:

In the editor, create a MeshInstance3D and add an ArrayMesh to it in the Inspector.

Please make sure you've read the tutorial properly

AlphaLuceatLaetis commented 1 month ago

I've read that part, of course. Anyway, it's odd that in Godot 4.2 MeshInstance3D.mesh.add_surface_from_arrays(...) doesn't exist, returning error. While you find that function under ArrayMesh. Hence, that is why I opened the issue. Did I miss anything, perhaps?

AThousandShips commented 1 month ago

You didn't follow that instruction:

add an ArrayMesh to it in the Inspector.

You added some other type probably

AlphaLuceatLaetis commented 1 month ago

I see, then it's all correct. My bad, it seemed that something was missing, a common issue when mixing editor and code together, thing get "hidden". I'm glad it's not an error, sorry for wasting your time.

AThousandShips commented 1 month ago

No worries! There could be some details to improve, like mentioning that mesh is a member property