I tested this in a new project, same thing happens if test = true, if you are trying this, note in the output:
[StaticBody:1211] c
[InputEventMouseMotion:1461] a
[InputEventMouseMotion:1461] b
it doesn't happends every time the game are running
var test = true
var m
var b
var a = load("res://a.tscn")
# a.tscn = Staticbody + MeshInstance + CollisionShape
onready var camera = $Camera
func get_pointed_object():
var mp = get_viewport().get_mouse_position()
var f = camera.project_ray_origin(mp)
var to = f + camera.project_ray_normal(mp) * 100
var s = get_world().direct_space_state.intersect_ray(f,to)
if s:
return s.collider
func _input(event):
print(m," a")
if event is InputEventMouseMotion:
print(m," b")
var s = get_pointed_object()
if s:
if m and is_instance_valid(m) and m.has_node("node"):
pass
m = s
print(m," c")
m.queue_free()
func _physics_process(delta):
if test or b == null or is_instance_valid(b) == false:
b = a.instance()
add_child(b)