I'm relatively new to godot engine and I've recently stumbled into a sort of an annoying problem.
I'm trying to set a nodes position based on a unprojectposition of camera.
I'm using global script activated as a singleton to store camera's id through camera's script.
Later the variable, camera's id, is used in GUI's script to show a button above the players head when he can interact with an object.
Player has different stages of interaction with an object: isinteracting, caninteract, isnot_interacting.
Now the error happens only if I try to set the button, at the time hidden, above the player at the start of the game. It is as the camera's script was still not initialized.
I tried preloading the camera asset and trying to run it as camera's id through the global script, but my attempts either failed or reproduced the same problem as before.
How would one go about loading the asset before main scene is initialized. Therefor, have the cameras id, before the script called for the unproject_position.
Here is the code that produces an error from the title:
onready var LABEL = $HBoxContainer/Elements/State/Box/Label
pos = global.player_pos
cam = global.cam_id
screenPos = cam.unproject_position(pos)
#this is the part that produces the error
LABEL.text = "State: "+global.player_state
if global.player_state == "can_interact":
if global.player_state == "is_interacting":
if global.player_state == "idle" || global.player_state == "is_moving":
And here is my attempt at preloading the camera scene through the global script (as well as some others):
onready var PLAYER = load("res://Objects/Player/Player.tscn")
onready var COPY_MACHINE = load("res://Objects/Assets/Office/Copy machine/copy_machine.tscn")
onready var CAMERA = load("res://Objects/Assets/Miscellaneous/Camera.tscn").instance()
onready var UI_F = load("res://UI/F_KEY.tscn")
cam_id = CAMERA
player_id = null
player_pos = null
player_state = "idle"
I might be going at this completely the wrong way, so any ideas or suggestions are greatly appreciated.