How to simulate a plant's growing?

Godot Version

v4.4.stable.official.4c311cbee

Question

On my game’s world scene I have a crop where seeds are planted and a plant should grow over time. My current and first thought is to assign different MeshInstance3D to the same scene and show/hide the correct one.
In example I have wheat, I have created a scene for it with 4 MeshInstance3D, all of them are just 4 CylinderMesh of different heights and colors called Mesh0, Mesh1, Mesh2, Mesh3.
Into the script assigned to the Wheat.tscn I have this code:

extends Plant

class_name Wheat

@onready var mesh0 = $Mesh0
@onready var mesh1 = $Mesh1
@onready var mesh2 = $Mesh2
@onready var mesh3 = $Mesh3

func _ready() -> void:
	mesh1.visible = false
	mesh2.visible = false
	mesh3.visible = false
	
	await get_tree().create_timer(3.0).timeout
	mesh0.visible = false
	mesh1.visible = true
	
	await get_tree().create_timer(3.0).timeout
	mesh1.visible = false
	mesh2.visible = true
	
	await get_tree().create_timer(3.0).timeout
	mesh2.visible = false
	mesh3.visible = true

The code could probably be better, but at the moment I want to understand if I’m on the right track or if there’s a better way to achieve my goal.
Do you have suggestions on how to proceed?

Swapping meshes is a good technique, you get even more by modulating the textures to fruitier colors over time, or increasing height too.

Instead of three seperate timers you could use one Timer function and a Array to index through. This script could also be applied to any plant that swaps meshes over a common time interval.

@export var meshes: Array[MeshInstance3D]
var mesh_index: int = 0

func _on_timer_timeout() -> void:
	if mesh_index < meshes.size():
		meshes[mesh_index].visible = false
		mesh_index += 1
		meshes[mesh_index].visible = true
2 Likes