Accesess to a node from another scene

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Boett

I am working on a fps hitscan gun that is a separate scene from the main player(KinematicBody).
The problem is that the raycast varies from gun to gun because of the possition of the gun,but I want the player to, no matter where the “bullet” is comming from, it will always be directed to the center of the screen.
To that end, I need to “connect” the gun raycast to the player raycast so all the guns will shoot towards the same point.
The problem is that when I try to call the player raycast node this message appears: onready var aimcast = $Aimcast// get_node: Node not found: Aimcast.
How can I call the AimCast node from the gun scene?

:bust_in_silhouette: Reply From: Scavex

How about you give this a shot ?

onready var aimcast= get_parent().get_node("AimCast")

I’m pretty new myself and not sure if it’ll be something that’s considered a good practice but you can save the AimCast as sperate branch by right clicking on it and selecting “Save Branch as Scene” and then instancing that to your scene where you want that. Then you can make that AimCast Local and make necessary adjustments or changes to it locally there. This way the above code should also work.

:bust_in_silhouette: Reply From: andrewtu0182

The simple way is this =


The longer way is this =

Remove the current level

var level = root.get_node("Level")

Add this

Add the next level

var next_level_resource = load("res://scene.tscn)
var next_level = next_level_resource.instance()