Setting multiple meshs to 1 varible

Godot Version

gd 4.0

Question

making an astroid with small meshinstance3d as ore cubes. trying to change the color of all of them under 1 mesh varible. is it possible to set all meshs under 1 varible to change

@onready var ore_mesh = $ore_mesh/ore, $ore_mesh/ore2, $ore_mesh/ore3, $ore_mesh/ore4, $ore_mesh/ore5, $ore_mesh/ore6
@export var astroid_ore_type = “”

#ore color stuf
var iron = preload(“res://assets/colors/iron_color.tres”)
var copper = preload(“res://assets/colors/copper_color.tres”)
var gold = preload(“res://assets/colors/gold_color.tres”)
var diamond = preload(“res://assets/colors/diamond_color.tres”)

Called when the node enters the scene tree for the first time.

func _ready():
#sets color of ore when spawned
if astroid_ore_type == “iron”:
ore_mesh.set_surface_override_material(0, iron)
if astroid_ore_type == “copper”:
ore_mesh.set_surface_override_material(0, copper)
if astroid_ore_type == “gold”:
ore_mesh.set_surface_override_material(0, gold)
if astroid_ore_type == “diamond”:
ore_mesh.set_surface_override_material(0, diamond)
Help? thanks

you can store the values in an array or dictionary. below i put stings in an array then iterate over each item, adding a “!”. finally i print the value

extends Node2D
var m_items : Array = ["One", "Two", "Three"]

func _ready():
	for j_index in range(m_items.size()):
		m_items[j_index] = m_items[j_index] + "!"
	
	for j_string in m_items:
		print(j_string)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.