The variable that I got from parent doesn't update

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

hello I am working on a game, and it was going decently but my camera system doesnt work, the parent variable doesn’t update

onready var game = get_parent()
onready var bonnie = game.bonnieRoom
var CamON = false
var cam = 1
var cooldown_done = true
onready var sprite = get_node("Sprite")

#Cam 01
var cam01_bonnie = load("res://Sprites/Camera/BonnieCam01.png")
var cam01 = load("res://Sprites/Camera/Cam01.png")

#Cam 02

var cam02_bonnie = load("res://Sprites/Camera/BonnieCam02.png")
var cam02 = load("res://Sprites/Camera/Cam02.png")


#Cam 03

#Cam 04

var cam04_bonnie = load("res://Sprites/Camera/BonnieCam04.png")
var cam04 = load("res://Sprites/Camera/Cam04.png")

#Cam 06

var cam06_bonnie = load("res://Sprites/Camera/BonnieCam06.png")
var cam06 = load("res://Sprites/Camera/Cam06.png")

func _physics_process(delta):
    bonnie = game.bonnieRoom
    if Input.is_action_pressed("camera"):
        if cooldown_done == true:
            if CamON == true:
                position.y = 128
                CamON = false
                cooldown_done = false
                $Timer.start(0.1)
            elif CamON == false:
                position.y = -256
                CamON = true
                cooldown_done = false
                $Timer.start(0.1)
    if cam == 1:
        if bonnie == 1:
            sprite.texture = cam01_bonnie
        else:
            sprite.texture = cam01
    print(bonnie)
func _on_Cam01_pressed():
    pass # Replace with function body.


func _on_Cam02_pressed():
    pass # Replace with function body.


func _on_Cam04_pressed():
    pass # Replace with function body.


func _on_Cam06_pressed():
    pass # Replace with function body.


func _on_Timer_timeout():
cooldown_done= true

Does your problem lie with the game variable? What is not updating?

Ertain | 2021-02-02 19:01

So “bonnie” variable doesn’t update when parent variable “bonnieRoom” updates

Afrent | 2021-02-02 19:04

I think you could use a WeakRef, or just bonnie = game.bonnieRoom again

whiteshampoo | 2021-02-03 08:45