Hmm, ok, so I changed a bit of code and have the first problem (almost) sorted, it didnt quite work as expected….
if scene_node != null:
caused an error, took a while to figure out….
if is_instance_valid(scene_node):
…is the correct way to check that.
It then worked, BUT, hundreds of nodes were created on a delta basis, not good! I changed things around to make sure only one node it created, I THINK that this is what its now doing, but not 100% sure!
extends Node2D
onready var scene = load("res://otherstuff/2ndLightBeam.tscn")
var scene_node = null
onready var node_pos = Vector2()
var has_instance :bool = false
func _physics_process(delta):
if $LightBeam.is_colliding() and has_instance == true:
pass
if $LightBeam.is_colliding() and has_instance == false:
print("colliding")
node_pos = get_node("Node2D").position
scene_node = scene.instance()
scene_node.position = Vector2(node_pos)
add_child(scene_node)
has_instance = true
print(scene_node, "... scene entered")
elif $LightBeam.is_colliding() == false:
print("not colliding")
if is_instance_valid(scene_node):
scene_node.queue_free()
has_instance = false
print(scene_node, "... is free")
I was pointed in the right direction with your answers tho!!
HOWEVER, this creates a problem I hadnt forseen… as we are detecting when the raycast hits an Area2D, the new instanced scenes are instantly detecting the Area2D on spawning as they are at the position of those nodes they collide with (where I want them!), and as I suspect, it immediately is queue_free’d….
In hindsight, seems this is basicly the laser and lens-companion-cube mechanics in portal im trying to create!
Now as these light beams are going to be colliding with and spawning from throughout many different Area2Ds im proper stuck if the raycast is deleted before it gets a chance to raycast! How do I get these Raycast lightbeams to both detect AND not detect the Area2Ds!??
Heres a pic for visual reference, the beam hits the first godot head(which can rotate) then spawns the new lightbeam which hits the next godot head, etc etc....

Dammit, I fell down the rabbit hole…