Await noise texture being updated

Godot Version

v4.4.stable.official [4c311cbee]

Question

Hi :slight_smile:

When i change a property of a NoiseTexture2D (during runtime), it takes a while until the texture is updated in the viewport. Up to half a second in my case. Do i have any possibility to wait for this update in code before continuing?

There are SubViewports in the middle if this is an important info. (ViewportTexture)

I know i could just wait a second, but that’s wonky.

You can use await RenderingServer.frame_post_draw to wait for the frame update.

I already did that, it does not help. There are many frames drawn before the noise texture is updated. As i said up to half a second.

A tween for example is executed and i can see the texture update in the middle of it. I would like to wait with the tween until the texture is ready.

You could use the Resource.changed signal. There is an example on the noise-texture page: NoiseTexture2D — Godot Engine (stable) documentation in English

1 Like

So, first: Thanks. Waiting for the Resource.changed signal helped. But it was a little more complicated in my case, as i have to wait for several of those threaded textures to be updated, without a lot of awaits blocking each other unnecessarily. Therefore i had to get creative. If there is any built in functionality i could replace this with, please tell me. Otherwise this might help others:


signal _await_queue_empty(group: StringName);
var _await_queue_id: int;
var _await_queue: Dictionary;	

func wait_for_await_queue(
	group: StringName = "main"
) -> void:
	if self._await_queue[group].size() > 0:
		while true:
			var g = await self._await_queue_empty;
			if g == group: return;

func add_to_await_queue(
	object: Object, 
	_signal: StringName, 
	group: StringName = "main"
) -> void:
	self._await_queue_id += 1;
	
	var method := func(key: int, group: StringName):
		var msg: Dictionary = self._await_queue[group][key];
		self._await_queue[group].erase(key);
		msg.object.disconnect(msg.signal, msg.method);
		if self._await_queue[group].size() == 0:
			self._await_queue_empty.emit(group);
			
	if !self._await_queue.has(group):
		self._await_queue[group] = {};
			
	self._await_queue[group][self._await_queue_id] = {
		"group": group, "method": method, "object": object, "signal": _signal 
	};		
	
	object.connect(_signal, method.bind(self._await_queue_id, group));