Godot Version
4.4
Question
Hi! I’m trying to make a rail system similar to the one in minecraft but in 2D. To detect if there is an object where you want to place a rail I’m doing this:
var data_map = tilemap.get_cell_source_id(1, rail_pos) #rail_pos is the position of the rail that is going to be placed in the tilemap
if data_map == -1:
#place_rail
This works perfectly except for objects in the tilemap that were previously freed. I have trees that are placed as a scene collection in the tilemap and that the player can break. The problem is that even when the trees are not there anymore it doesn’t let me place a rail where they were.
The code for the trees is this, in case you’re interested
extends StaticBody2D
@export var hp : int = 3
@export var gives : int = 3
func hit():
hp -= 1
vfx.damagfe_vfx($Sprite2D)
if hp <= 0:
dissapear()
func dissapear():
globals.wood += gives
$Sprite2D.hide()
$CollisionShape2D.disabled = true
$CPUParticles2D.emitting = true
func _on_cpu_particles_2d_finished() -> void:
print("queue free")
queue_free()
What can I do? Thanks!