0 votes

Hey there

So I have an hboxcontainer, with a custom separation I'd like to set through script, and it works fine. The weird behaviour comes in when I try to use an onready var as reference for the hboxcontainer.

The following code works:

func _ready():
    $Control/HBoxContainer.add_constant_override("separation", get_viewport().size.x-100)


func _on_HBoxContainer_resized():
    $Control/HBoxContainer.add_constant_override("separation", get_viewport().size.x-100)

while this does not:

onready var h_container = $Control/HBoxContainer


func _ready():
    h_container.add_constant_override("separation", get_viewport().size.x-100)


func _on_HBoxContainer_resized():
    h_container.add_constant_override("separation", get_viewport().size.x-100)

with the following error message being flagged on the onHBoxContainer_resized() signal:

Invalid call. Nonexistent function 'add_constant_override' in base Nil.

Anyone able to shed light on why this happens?

Godot version Godot 3.4.4
in Engine by (19 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.