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
Describe the bug
In Tiled I can define a Tiled object that is of class instance and has a res_path that is of type File and points to a .tscn. Tiled will save the file path as a relative path from where the Tiled object is defined. If I save this Tiled object as a template .tx file and place the template in a different folder to the tilemap, then the res_path relative path will be pointing to the .tscn file from within the template directory .tx. This means that the instancing of the scene will fail because the importer expects the scene res_path to be relative to the map .tmx file.
Standard Example:
/maps/map1.tmx
/scenes/object.tscn
In map1.tmx I add an object layer with a point object of class instance and res_path = "../scenes/object.tscn"
If I then save that point object as a template:
/maps/templates/objtemplate.tx
then tiled makes res_path = "../../scenes/object.tscn and YATI will try to load this res-path from the /maps directory which is where the map1.tmx is being created. This will cause a scene import error because res_path is going up 2 directories now.
To Reproduce
Steps to reproduce the behavior:
create a tilemap tmx file
add a point Object in an object layer, setting class=instance and setting custom File property res_path pointing to a godot .tscn file
right click on the object in Tiled and choose "Save as template"
Save the template in a subfolder such as templates/
Reload the godot project -> YATI will complain that it could not find the .tscn file.
Expected behavior
The issue is the res_path being used to load the .tscn:
# approx - line 676 in TilemapCreator.gdvarscene=load_resource_from_file(res_path)
YATI should adjust the res_path to be relative to the template.tx folder rather than the tilemap.tmx file when the object being instantiated is defined from within a template.
Examle map (zipped)
A zip file containing a small but complete example to reproduce the issue.
This could accelerate resolving it.
Working fix / hack
This is inside TilemapCreator.gd at about line 647 onwards. See the added # comments with the proposed fix.
ifobj.has("template"):
vartemplate_path=_base_path.path_join(obj["template"])
vartemplate_dict=preload("DictionaryBuilder.gd").new().get_dictionary(template_path)
vartemplate_tileset=nulliftemplate_dict.has("tilesets"):
vartilesets=template_dict["tilesets"]
vartileset_creator=preload("TilesetCreator.gd").new()
tileset_creator.set_base_path(template_path)
tileset_creator.set_map_parameters(Vector2i(_map_tile_width, _map_tile_height))
if_map_wangset_to_terrain:
tileset_creator.map_wangset_to_terrain()
template_tileset=tileset_creator.create_from_dictionary_array(tilesets)
iftemplate_dict.has("objects"):
fortemplate_objintemplate_dict["objects"]:
# FIX begin# since we are loading this object from a template file, save the template file's# directory path as additional data on the template_obj so that if the template# makes use of custom properties of type File, then the file paths can be computed correclty# since they would be relative to the folder containing the template .tx filetemplate_obj["template_dir_path"] =template_path.get_base_dir()
handle_object(template_obj, layer_node, template_tileset, Vector2(obj_x, obj_y))
# v1.2: New class 'instance'ifgodot_type==_godot_type.INSTANCEandnotobj.has("template") andnotobj.has("text"):
varres_path=get_property(obj, "res_path", "file")
ifres_path=="":
printerr("Object of class 'instance': Mandatory file property 'res_path' not found or invalid. -> Skipped")
_error_count+=1else:
ifobj.has("template_dir_path"):
# FIX Continued...# when the INSTANCE is from a template, then res_path will be the relative path to the .tscn file# from the folder containing the template.tx file # hence, res_path should be template_dir_path + res_pathres_path=obj.template_dir_path.path_join(res_path)
varscene=load_resource_from_file(res_path)
Will try and create a minimal project to test this
The text was updated successfully, but these errors were encountered:
I have created a minimal example showcasing the issue. The attached zip has the fix code written, but commented out, thus showcasing the import error (note: you may need to open the tiled project, drag the map object and save in tiled to trigger a reload with the error).
You can then search for # TEMPLATE PATH FIX to find where to uncomment the code for the fix. After updating, you may need to restart godot, and ensure YATI reloads the map.
Describe the bug
In Tiled I can define a Tiled object that is of class
instance
and has ares_path
that is of type File and points to a.tscn
. Tiled will save the file path as a relative path from where the Tiled object is defined. If I save this Tiled object as a template.tx
file and place the template in a different folder to the tilemap, then theres_path
relative path will be pointing to the.tscn
file from within the template directory.tx
. This means that the instancing of the scene will fail because the importer expects the sceneres_path
to be relative to the map.tmx
file.Standard Example:
In
map1.tmx
I add an object layer with a point object of classinstance
andres_path = "../scenes/object.tscn"
If I then save that point object as a template:
then tiled makes
res_path = "../../scenes/object.tscn
and YATI will try to load this res-path from the/maps
directory which is where themap1.tmx
is being created. This will cause a scene import error because res_path is going up 2 directories now.To Reproduce
Steps to reproduce the behavior:
class=instance
and setting custom File propertyres_path
pointing to a godot.tscn
filetemplates/
.tscn
file.Expected behavior
The issue is the res_path being used to load the .tscn:
YATI should adjust the res_path to be relative to the template.tx folder rather than the tilemap.tmx file when the object being instantiated is defined from within a template.
Examle map (zipped)
A zip file containing a small but complete example to reproduce the issue.
This could accelerate resolving it.
Working fix / hack
This is inside
TilemapCreator.gd
at about line 647 onwards. See the added#
comments with the proposed fix.Will try and create a minimal project to test this
The text was updated successfully, but these errors were encountered: