diff --git a/src/Classes/Cel3D.gd b/src/Classes/Cel3D.gd index 1dd487d80..273cb017d 100644 --- a/src/Classes/Cel3D.gd +++ b/src/Classes/Cel3D.gd @@ -118,19 +118,22 @@ func _scene_property_changed() -> void: # Called by undo/redo func _add_object_node(id: int) -> void: + if not object_properties.has(id): + print("Object id not found.") + return var node3d := Cel3DObject.new() node3d.id = id node3d.cel = self parent_node.add_child(node3d) - node3d.type = object_properties[id]["type"] - if object_properties.has(id): - if object_properties[id].has("id"): - node3d.deserialize(object_properties[id]) - else: - if object_properties[id].has("transform"): - node3d.transform = object_properties[id]["transform"] - if object_properties[id].has("file_path"): - node3d.file_path = object_properties[id]["file_path"] + if object_properties[id].has("id"): + node3d.deserialize(object_properties[id]) + else: + if object_properties[id].has("transform"): + node3d.transform = object_properties[id]["transform"] + if object_properties[id].has("file_path"): + node3d.file_path = object_properties[id]["file_path"] + if object_properties[id].has("type"): + node3d.type = object_properties[id]["type"] object_properties[id] = node3d.serialize() emit_signal("objects_changed") diff --git a/src/Classes/Cel3DObject.gd b/src/Classes/Cel3DObject.gd index d8ba2acf6..694e38771 100644 --- a/src/Classes/Cel3DObject.gd +++ b/src/Classes/Cel3DObject.gd @@ -107,10 +107,10 @@ func serialize() -> Dictionary: func deserialize(dict: Dictionary) -> void: id = dict["id"] + file_path = dict["file_path"] self.type = dict["type"] transform = dict["transform"] visible = dict["visible"] - self.file_path = dict["file_path"] if _is_mesh(): var mesh: Mesh = node3d_type.mesh match type: @@ -164,6 +164,8 @@ func _is_mesh() -> bool: func _set_type(value: int) -> void: + if type == value and is_instance_valid(node3d_type): # No reason to set the same type twice + return type = value if is_instance_valid(node3d_type): node3d_type.queue_free()