0 votes

Hi there,

For reusability I have made a custom checkbox and saved it as a scene CustomCheckBox.tscn.
It is built like this:

I've added this custom checkbox to my MainScene multiple times.

The problem is that setting the Focus Neighbour Left, Right, Top Bottom values on any of the CustomCheckBox instances in the MainScene doesn't do anything.

I've realized that changing the Focus Neighbour setting on the instance of a CustomCheckBox in the main scene is only passed to the root node of the CustomCheckBox scene which is the CenterContainer in this case.
To fix this I've added a script to the CenterContainer of the CustomCheckBox scene to pass down the values to the checkbox control:

extends Control

func _ready():
    var cb = get_node("CheckBox")
    cb.focus_neighbour_left = self.focus_neighbour_left
    cb.focus_neighbour_right = self.focus_neighbour_right
    cb.focus_neighbour_top = self.focus_neighbour_top
    cb.focus_neighbour_bottom = self.focus_neighbour_bottom

This sets the focus neighbour properties, but when there is a focus change in a direction that has a value I get this error:

E 0:00:04.705 getnode: Node not found: ../CustomCheckBoxc.
<C++ Error> Condition "!node" is true. Returned: __null
<C++ Source> scene/main/node.cpp:1381 @ get_node()

I guess the problem has to do with how nodes see eachother's path at runtime in different scenes but I don't know the solution.

Could anyone help?

Godot version v3.2.3
in Engine by (15 points)

1 Answer

+1 vote
Best answer

First off, if you right click on your instance in the node tree and check "Editable children", you will be able to set the focus neighbors of the check box directly.

Second, it's possible that not all the nodes are ready when the ready function is called, causing that error. You'll know if all the checkbox instances are ready when their shared parent's ready function is called.

by (8,150 points)
selected by

Setting the "Editable children" was all I needed. Thanks!

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.