diff --git a/Assets/LDtkUnity/CHANGELOG.md b/Assets/LDtkUnity/CHANGELOG.md index 7f58a0b25..1d31cb553 100644 --- a/Assets/LDtkUnity/CHANGELOG.md +++ b/Assets/LDtkUnity/CHANGELOG.md @@ -1,3 +1,7 @@ +# 4.0.2 +###### September 28, 2023 +- Added safety-check if a tileset definition's relPath was null or empty + # 4.0.1 ###### September 28, 2023 - Updated json support for [LDtk 1.4](https://ldtk.io/json/#changes;1.4.0) diff --git a/Assets/LDtkUnity/Editor/ScriptedImporter/LDtkTilesetImporter.cs b/Assets/LDtkUnity/Editor/ScriptedImporter/LDtkTilesetImporter.cs index 2cdc95a77..3e09ce7a9 100644 --- a/Assets/LDtkUnity/Editor/ScriptedImporter/LDtkTilesetImporter.cs +++ b/Assets/LDtkUnity/Editor/ScriptedImporter/LDtkTilesetImporter.cs @@ -83,6 +83,7 @@ private static string[] GatherDependenciesFromSourceFile(string path) } //this depends on the texture + //todo add a digger for getting the RelPath LDtkProfiler.BeginSample($"GatherDependenciesFromSourceFile/{Path.GetFileName(path)}"); string texPath = PathToTexture(path); texPath = !File.Exists(texPath) ? string.Empty : texPath; @@ -408,8 +409,14 @@ private bool DeserializeAndAssign() return false; } + if (_json.RelPath.IsNullOrEmpty()) + { + Logger.LogError($"The tileset relative path was null or empty! Try fixing the Tileset path in the LDtk editor for \"{assetPath}\""); + return false; + } + Profiler.BeginSample("GetTextureImporter"); - string path = PathToTexture(assetPath); + string path = PathToTexture(assetPath, _json); if (LDtkRelativeGetterTilesetTexture.IsAsepriteAsset(path)) { @@ -452,9 +459,13 @@ private bool DeserializeAndAssign() /// /// Only use when needed, it performs a deserialize. look at optimizing if it's expensive /// - private static string PathToTexture(string assetPath) + private static string PathToTexture(string assetPath, TilesetDefinition def = null) { - TilesetDefinition def = FromJson(assetPath).Def; + if (def == null) + { + def = FromJson(assetPath).Def; + } + if (def.IsEmbedAtlas) { string iconsPath = LDtkProjectSettings.InternalIconsTexturePath; @@ -553,7 +564,7 @@ private bool HasTextureIssue(TextureImporter textureImporter, TextureImporterPla private Texture2D LoadTex(bool forceLoad = false) { - //in case the importer was destroyed via file delete + //this is important: in case the importer was destroyed via file delete if (this == null) { return null;