Hi I’m new to Godot and I’m trying to implement a feature that allows the player to teleport from one object to another object once they touch it. My issue is is that I keep getting a null error that states the object doesn’t exist even though I already added it to the scene. I don’t know if this is a hierarchy issue or something like that but I’ve been trying everything and I don’t know what’s wrong.
Here’s the code for the object the player teleports from
When the script is loaded, the scene is not completly loaded, hence the null exception. You solve this by either setting the reference in _ready() - function or using the handy @onready-annotation as mentioned above by @shatteredreality
@onready var refrac_position = get_node("Refrac").position
or
var refrac_position: Vector2 = Vector2.ZERO
func _ready():
refrac_position = get_node("Refrac").position
[quote=“J.G.S, post:4, topic:46696”] @onready var refrac_position = get_node("Refrac").position
[/quote] Thank you I got it working now, just need to tweak collision a bit