Godot Version
4.6
Question
I have a variable I tried to make global (I am aware of the Globals tab in settings, I did that first) , as I wanted to use in a different area, two actually, which I’m unsure how to reference in other scripts globally as I need the info in these variables to instance other objects in the same spot. One of them is in a custom function, so its not accessible by normal means, and I need the info of the variable to be accessed after the specific object is instanced to spawn other objects in that same position.
I have an example here of another variable that is not within a function though that i also am unable to access globally, and I’m unsure why its returning a null value:
#spawn_mesh is the variable I want to reference elsewhere, unsure how to make it so that I can do all of that outside of a function.
func spawn_enemy_instance():
#var shuffle : Array = [point_1,point_2,point_3]
for i in range(0,3):
var spawn_mesh : Node = mesh_scene.instantiate()
add_child(spawn_mesh)
spawn_mesh.position = SpawnmeshGlobal.shuffle.pick_random()
var spawn : Node = target_scene.instantiate()
#if get_tree().paused:
add_child(spawn)
spawn.position = spawn_mesh.position
And here, is the variable I made to get 3 positions in 3d to instance spawn_mesh at. However, I wanted to make the shuffle variable a global one so I could use it elsewhere, but upon doing so I was given null value.
@onready var point_1: MeshInstance3D = %Point1
@onready var point_2: MeshInstance3D = %Point2
@onready var point_3: MeshInstance3D = %Point3
var shuffle: Array = [point_1,point_2,point_3]
#point_1,point_2 and point_3 are placeholder meshes in 3d space to mark positions to instance the spawn_mesh at
Basically I would like to know a.) How can/how should I reference arrays containing positions globally? and b.) How can I reference variables within specific functions elsewhere, and if not, how should I go about making the variable global so that I can get attributes from it?(such as position)
Thank you for reading.
