You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My team is working on a private project that imports LDtk levels using the Godot LDtk Importer plugin. At the moment, our LDtk project is set to export each level to separate files.
The import process works as intended, but for every re-import, this error message shows up in Godot output:
res://addons/ldtk-importer/src/tileset.gd:319 - Unable to iterate on object of type 'Nil'.
Full log:
Godot Engine v4.3.stable.official (c) 2007-present Juan Linietsky, Ariel Manzur & Godot Contributors.
--- Debug adapter server started on port 6006 ---
--- GDScript language server started on port 6005 ---
Add Autoload
Godot-LDtk-Importer 2.0.1 (c) 2023 Andrew Gleeson.
res://addons/ldtk-importer/src/tileset.gd:319 - Unable to iterate on object of type 'Nil'.
[LDTK] Start Import: 'res://world/world.ldtk'
• LDTK VERSION (1.5.3) OK ✔
• Saving Tilesets: ["tileset_16px"]
‣ Entity Post-Import: Level0.Player
‣ Entity Post-Import: Level0.DynamicEnvironment
‣ Entity Post-Import: Level0.Collectibles
‣ Entity Post-Import: Level0.Locations
‣ Generated Locations
‣ Level Post-Import: Level0
‣ Processing Level
‣ Excluded layer 'FloorMapInvalids'
‣ Excluded layer 'FloorMap'
• Could not resolve 3 references, most likely non-existent entities.
• Saving Levels: [&"Level0"]
• Saving World 'res://.godot/imported/world.ldtk-a3a9fb77576c8abcabc7332360bd86e9'
[LDTK] Finished Import. (Total Time: 215ms)
On further investigation, I realized that the function get_tileset_overrides() in addons\ldtk-importer\src\tileset.gd is trying to access the JSON field world_data.levels->layerInstances in the .ldtk project file. This is returning Nil, because the actual data for each level is saved externally for my project. So the data in layerInstances still exists, but it is just saved in an external file.
Since I saw that the plugin has the capability to check for external levels (var external_level at func _import() in addons\ldtk-importer\ldtk-importer.gd:200) and parse external levels with LevelUtil.get_external_level(), I suppose it could be expected that loading tileset overrides would behave the same way for separated level files.
To Reproduce
Clone the plugin's repository.
Open the example GridVania project under examples/gridvania/example_gridvania.ldtk with LDtk, go into Project Settings, check "Save levels to separate files":
Save the LDtk project (Ctrl+S).
Open the repository in Godot, in FileSystem (1) with the examples/gridvania/example_gridvania.ldtk file selected (2), go to the Import (3) dock and press Reimport (4):
Modify get_tileset_overrides() to accept base_dir and external_levels as arguments, then load the level data accordingly:
# Collect all layer tileset overrides. Later we'll ensure these sources are included in TileSet resources.staticfuncget_tileset_overrides(
world_data: Dictionary,
base_dir: String,
external_levels: bool
) ->Dictionary:
varoverrides:= {}
forlevel_indexinrange(world_data.levels.size()):
varlevel_datalevel_data=world_data.levels[level_index]
ifexternal_levels:
level_data=LevelUtil.get_external_level(level_data, base_dir)
forlayerinlevel_data.layerInstances:
iflayer.overrideTilesetUid==null:
continuevargridSize: int=layer.__gridSizevaroverrideUid: int=layer.overrideTilesetUidifoverrideUid!=null:
ifnotoverrides.has(gridSize):
overrides[gridSize] = []
vargridsize_overrides: Array=overrides[gridSize]
ifnotgridsize_overrides.has(overrideUid):
gridsize_overrides.append(overrideUid)
returnoverrides
This would need some additional modifications to addons\ldtk-importer\ldtk-importer.gd to pass in base_dir and external_levels as parameters.
This is the current fix I am using in my project. Please let me know if this is the intended design for the plugin. If so, I can create a fork and make a PR for this.
System Information
Windows 10/11
Godot v4.3.stable.official [77dcf97d8] (x86_64) installed via scoop
LDtk 1.5.3-64bits
Godot LDtk Importer 2.0.1
(Btw, thanks for the amazing work on this plugin!)
The text was updated successfully, but these errors were encountered:
miketvo
added a commit
to miketvo/godot-ldtk-importer
that referenced
this issue
Dec 4, 2024
Since I have some extra time today, I've decided to go ahead and fork the repository and made the fix in #46. Please feel free to dismiss this if it is not the intended behavior of the plugin.
Description
My team is working on a private project that imports LDtk levels using the Godot LDtk Importer plugin. At the moment, our LDtk project is set to export each level to separate files.
The import process works as intended, but for every re-import, this error message shows up in Godot output:
Full log:
On further investigation, I realized that the function
get_tileset_overrides()
inaddons\ldtk-importer\src\tileset.gd
is trying to access the JSON fieldworld_data.levels->layerInstances
in the.ldtk
project file. This is returningNil
, because the actual data for each level is saved externally for my project. So the data inlayerInstances
still exists, but it is just saved in an external file.Since I saw that the plugin has the capability to check for external levels (
var external_level
atfunc _import()
inaddons\ldtk-importer\ldtk-importer.gd:200
) and parse external levels withLevelUtil.get_external_level()
, I suppose it could be expected that loading tileset overrides would behave the same way for separated level files.To Reproduce
examples/gridvania/example_gridvania.ldtk
with LDtk, go into Project Settings, check "Save levels to separate files":Ctrl+S
).FileSystem
(1) with theexamples/gridvania/example_gridvania.ldtk
file selected (2), go to theImport
(3) dock and pressReimport
(4):Potential Solution
Modify
get_tileset_overrides()
to acceptbase_dir
andexternal_levels
as arguments, then load the level data accordingly:This would need some additional modifications to
addons\ldtk-importer\ldtk-importer.gd
to pass inbase_dir
andexternal_levels
as parameters.This is the current fix I am using in my project. Please let me know if this is the intended design for the plugin. If so, I can create a fork and make a PR for this.
System Information
(Btw, thanks for the amazing work on this plugin!)
The text was updated successfully, but these errors were encountered: