Invalid assignment of property or key 'visible' with value of type 'bool' on a base object of type 'bool'.

This was originally a help query, however I figured out what I did wrong and decided to post my question + the solution for anyone who may have the issue in the future.

Godot Version

Godot 4.3-stable

Question

Hello! I have a Control node in my level and for some reason when I try to set it’s visibility I get the error “Invalid assignment of property or key ‘visible’ with value of type ‘bool’ on a base object of type ‘bool’.”

I can call it on the node’s path in the tree directly using $ it doesn’t have any errors, but my @onready variable with the same path throws the error. All of my other nodes (including controls) have no issues. I had this issue while running 4.2, however the error was slightly different (just wording).

Solution

One of my troubleshooting steps was to replace all instances of my variable with the tree path, and I found that in one spot instead of assigning a bool to .visible I was assigning it directly to the variable. more static typing would be helpful to prevent this issue in the future. Hope this helps someone in the future!

After solving the issue, I looked closer at the error (the 4.2 error was more ambiguous, but it seemed to be saying basically the same thing when I updated so I didn’t read the 4.3 version very closely) and the error makes it clear that I was trying to access visible withing a boolean type. So I feel a little dumb.

As you said, with a type declaration, this would not have happened.

@onready var MyNode: Control = $ControlNode

MyNode = true  # This will throw an error in the Editor

Parser Error: Value of type "bool" cannot be assigned to a variable of type "Control".

If you remove the :Control, the variable will just be re-assigned to a bool.


@onready var myNode = $ControlNode

func _ready():
	myNode = true
	print(myNode) # no errors or warnings.

So I agree, always use type annotations or type hints. They make a massive difference!

Paul.