Godot 3 to 4 rename
StreamTexture2D in Godot 4: it is CompressedTexture2D now
StreamTexture2D is called CompressedTexture2D in Godot 4.7.2, and the editor's parse error names it. It is the texture Godot loads from the .ctex file its import system writes for an imported image.
What Godot prints
A script that creates a StreamTexture2D, the name the converter knows for what Godot 4 calls CompressedTexture2D.
extends Node
func _ready():
var tex = StreamTexture2D.new()
print(tex.get_class())
SCRIPT ERROR: Parse Error: Identifier "StreamTexture2D" not declared in the current scope. Did you mean to use "CompressedTexture2D"?
at: GDScript::reload (res://answers/streamtexture2d-in-godot-4/repro.gd:4)
ERROR: Failed to load script "res://answers/streamtexture2d-in-godot-4/repro.gd" with error "Parse error".
at: load (modules/gdscript/gdscript_resource_format.cpp:46)The fix
The same texture as CompressedTexture2D, a Texture2D like every other 2D texture.
extends Node
func _ready() -> void:
var tex := CompressedTexture2D.new()
print(tex.get_class(), " is a Texture2D: ", tex is Texture2D)
print("size before a file is loaded: ", tex.get_size())
CompressedTexture2D is a Texture2D: true
size before a file is loaded: (0.0, 0.0)Why it happens
GDScript's analyzer resolves every identifier when the script loads. StreamTexture2D is not a class in Godot 4.7.2, so the script fails to parse and Godot does not load it.
The editor build looks an unknown identifier up in Godot's own 3 to 4 rename tables and adds the new name to the error: Did you mean to use "CompressedTexture2D"? The table maps both StreamTexture and StreamTexture2D to CompressedTexture2D.
CompressedTexture2D is loaded from a .ctex file, a format internal to Godot that the import system creates from other image formats. One made with new() has no file behind it, which is why the fix printed a size of (0.0, 0.0).
The import settings pick its compression: Lossless, Lossy, VRAM Compressed, VRAM Uncompressed or Basis Universal. Only VRAM Compressed reduces the memory the texture takes on the GPU.
Sources
Run on Godot 4.7.2, .