Godot 3 to 4 rename
BakedLightmapData in Godot 4: it is LightmapGIData now
BakedLightmapData is LightmapGIData in Godot 4.7.2, and BakedLightmap is LightmapGI. Do not create it in code: a bake writes it into the LightmapGI node's light_data, which is null until then, as the fix printed.
What Godot prints
A Godot 3 script that creates a BakedLightmapData in code, on a Node3D.
extends Node3D
func _ready():
var data = BakedLightmapData.new()
print(data)
SCRIPT ERROR: Parse Error: Identifier "BakedLightmapData" not declared in the current scope. Did you mean to use "LightmapGIData"?
at: GDScript::reload (res://answers/bakedlightmapdata-in-godot-4/repro.gd:4)
ERROR: Failed to load script "res://answers/bakedlightmapdata-in-godot-4/repro.gd" with error "Parse error".
at: load (modules/gdscript/gdscript_resource_format.cpp:46)The fix
In Godot 4 the data belongs to a LightmapGI node and is written by a bake. The fix adds a LightmapGI and reads its light_data, typed as LightmapGIData.
extends Node3D
func _ready() -> void:
var gi := LightmapGI.new()
add_child(gi)
var data: LightmapGIData = gi.light_data
print("light_data before a bake: ", data)
print("LightmapGIData extends ", ClassDB.get_parent_class("LightmapGIData"))
light_data before a bake: <Object#null>
LightmapGIData extends ResourceWhy it happens
GDScript's analyzer resolves every identifier when the script loads. BakedLightmapData is not a class in Godot 4.7.2, so the script fails to parse and Godot does not load it. The editor build adds the new name from Godot's 3 to 4 rename table: Did you mean to use "LightmapGIData"?
The table maps BakedLightmap to LightmapGI and BakedLightmapData to LightmapGIData.
LightmapGIData holds the baked lightmap and the dynamic object probe data of a LightmapGI, and every bake replaces it. The class reference says light_data is created automatically after baking and is not meant to be created manually. It is a Resource, as the fix printed.
Baking a LightmapGI is only available in the editor, so an exported game cannot bake lightmaps. For procedurally generated or user-built levels, the class reference points to VoxelGI or SDFGI instead.
Sources
- renames_map_3_to_4.cpp line 1485, BakedLightmapData to LightmapGIData
- renames_map_3_to_4.cpp line 1484, BakedLightmap to LightmapGI
- gdscript_analyzer.cpp line 4687, the error with the rename hint
- LightmapGIData class reference
- LightmapGI.light_data, created by a bake
- LightmapGI class reference, baking in the editor only
Run on Godot 4.7.2, .