Retrieving Image Data From NoiseTexture2D returns Null

Godot Version

Godot v4.2.1.stable

Question

I am trying to retrieve image data from a NoiseTexture2D. I seem to be able to get an image resource, but as soon as I try to get the associated data via Image.get_data(), it only returns null
I am aware, that image generation is run on a separate thread, so I tried using await texture.changed to see if that helps, but the result is either the same.

The relevant code snippets:

@onready var _map_image: Sprite2D = $"MapBackground/MapLayer/MapImage":
	get:
		return _map_image

var _map_noise_image: Image

func _ready() -> void:
     await _map_image.texture.changed # does not solve the problem
	_map_noise_image = _map_image.texture.noise.get_image(
	_map_image.texture.get_width(), _map_image.texture.get_height(), false, true)

     get_heightmap_data()
       
func get_heightmap_data():
    # returns null on non null image
    var heightmap_data = _map_noise_image.get_data() 
    return heightmap_data

I’d be grateful for any pointers as to where I might be going wrong here

Hi,
I’m not sure this is going to be your problem, but the issue I fell into with this is that once you define a NoiseTexture2D, you then within it need to define a “Noise”, e.g. create a FastNoiseLite in the noise slot.

Thank you for your reply, but the Sprite2D Node has a NoiseTexture, in which the noise is defined.

I cannot reproduce your issue (4.2.1.stable.arch_linux).

Created a new scene (just a Node2D), added a Sprite2D as its child and added your code (while changing the path for _map_image, of course). Then gave the sprite a new NoiseTexture2D with FastNoiseLite and ran the scene: everything worked!

(And yes, it also works without the await.)

That’s really strange… that’s exactly the setup I have and I’m not modifying the image anywhere.

I “solved” it. It seems that it was only the debugger (both in VSCode and the editor) displaying the image data as null, while retrieving and printing the array and some values returned what I would would have expected.

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