I have an export variable and a global variable. I try to assign the global variable equal to the export variable on ready in the script with the export variable. It works at first, but the next tick it resets to the export default.
Can't assign export variable to global variable
- Edited
xyz
Script 1 export var
@export var npcpath2 := "World/Enviroment/Man1/Center"
func _ready():
global.npcpath = npcpath2
changed to Man2 in inspector
Global Script var
var npcpath = TYPE_STRING
Script 2
target_node = get_tree().get_root().get_node(global.npcpath)
xyz My bad, I didn't mean to leave that in, it's supposed to be an empty string
var npcpath = " "
I have 2 print statements to check the value of the global variable, one in ready, which correctly displays it, and one in process delta where it shows the variable being set back to default. I tried putting the global var = export var code in process delta, and the print statement showed it alternating back and forth between the default and what I set it to in the editor. Example:
World/Enviroment/Man1/Center
World/Enviroment/Man2/Center
World/Enviroment/Man1/Center
World/Enviroment/Man2/Center
That is what the output log would look like
HeroRyker I realize I misunderstood your question, the point of this variable is the get the global position on a node, and I want to have the node it's checking for be editable in the editor. It seems the best way to do that is to use node_path so I made the export variable a string, the global variable a string, and when it checks for what node to get the position of, it uses get_node(global.npc).global_transform.origin, which works just fine, but if I try to change the export variable in the inspector, it will just reset back to default next tick.
xyz Not right now, but I'll send it here in a bit.
Hey I figured it out while making the MRP! I didn't realize that setting the variable on ready would make it so you're trying to assign 2 separate values to one variable, I moved some of the code around so that the global variable only gets set right before I interact with the person, and it works perfectly! Sorry for wasting your time.