+1 vote

Hello,
I'm wondering if there is a good way to view GDScript's SurfaceTool generated mesh in the editor for easier visual manipulation/placement of that procedurally generated mesh.

Adding 'tool' to the top of the GDScript file that generates the mesh for a MeshInstance node appears to somewhat work by causing the script to be executed in editor each time the scene file is opened. But this appears to cause the generated mesh to be stored in the .tscn file when the scene is saved, which makes the file unnecessarily big.

I can manually clear the MeshInstance's Mesh field every time I'm saving the scene but feels like there should be a better way that I'm missing...
Thanks.

asked May 18 in Engine by dev.monkey (13 points)

1 Answer

0 votes

I think it depends on how you structured your code, are you triggering the mesh generation at func _ready? Then it's normal.
If not, I'd say paste here some of your code, so that I can help more.
I can tell you that in my case I used properties (export, with onready), and used them to trigger the mesh generation function only when value is changed (using setget), so, for example:

tool
extends Spatial

export(bool) onready var trigger_generation= false setget GenerateMesh


func GenerateMesh(_newval):
    if(_newval != trigger_generation):
        callMeshGenerationFunction()
answered Jul 7 by Toshio Araki (14 points)
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.