How to copy ViewportTexture

Godot Version

4.2

Question

Try to I started googling my problem. I kind of found a solution by copying it to ImageTexture.

	public static Texture GetPhoto(in Vector2 cameraPosition, in Vector2 zoom = default)
	{
		var camera = MainAPINPCPhoto.GetCamera2D();
		
		var newZoom = zoom;
		if (newZoom == default)
			newZoom = new Vector2(45, 30);
		
		camera.Zoom = newZoom;
		camera.Position = cameraPosition;
		
		var texture = MainAPINPCPhoto.GetTexture() as Texture2D;
		var image = texture.GetImage();
		var imageTexture = ImageTexture.CreateFromImage(image);
		return imageTexture;
	}

However, Image corresponds to the previous point. Each time I change the position of the camera, the texture itself corresponds to a point on the map, but the Image I get from the same texture corresponds to the previous point.
How to get a non-changing ViewportTexture? as many details as possible

Try awaiting the signal RenderingServer.frame_post_draw before accessing the texture.

I don’t understand how to wait for a signal. The function is called in a different class, and that function must return an ImageTexture. I don’t really understand how to properly wait for the RenderingServer.FramePostDraw signal inside this function.

When i get a texture using the GetTexture function, it is correct. But when you get an image from it, a completely different texture comes out.

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