Changing texture


I want to put a texture on a wall in my godot scene.
Then I want code that loops through all images (jpg or png) in a folder and shows each picture on the texture (for example waiting 10 seconds between the change)

Can somebody tell me what I need to put in the godot editor and what code I need for this? I’m not using C#

You will need to use DirAccess. there is a great example for iterating through files in a directory there.

Reference your mesh’s material through @export or $MyMeshNodeName. Change it’s albedo_texture property to one loaded by the DirAccess script/loop.

A Timer will be needed to delay the change.

is it asked too much to give me a code example?
i’m not a devloper and use godot just to create a scene to walk’around (not a real interactive game).
this is the only code I need :slight_smile:

1 Like
extends GeometryInstance3D

@onready var timer: Timer = $Timer
@export_dir var images_path: String
@export var image_extensions: Array[String] = ["png", "jpg"]

var found_images: Array[Texture2D] = []
var material: StandardMaterial3D

func _ready() -> void:

	var dir =
	assert(dir, "Could not open path '%s' to look for images!" % images_path)
	var file_name = dir.get_next()
	while file_name != "":
		if not dir.current_is_dir():
			if file_name.get_extension() in image_extensions:
				var image := load(images_path.path_join(file_name)) as Texture2D
				if image:
		file_name = dir.get_next()

	# Use existing material override if applicable
	if material_override is StandardMaterial3D:
		material = material_override
		material =
		material_override = material

var images_idx: int = 0
func _on_timer_timeout() -> void:
	images_idx += 1
	images_idx %= found_images.size()
	material.albedo_texture = found_images[images_idx]

Here is a script that goes on a MeshInstance3D or CSG shape, it assumes there is a Timer as a child of said Node. Check the inspector for exported properties, a path must be provided.

1 Like

Thanks so much!!!

doing The Kirby Dance…

(>‘-’)> <(‘-’<) ^(’ - ‘)^ <(’-‘<) (>’-')>

1 Like