-
-
Notifications
You must be signed in to change notification settings - Fork 20.2k
-
-
Notifications
You must be signed in to change notification settings - Fork 20.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exported variables break setget methods that are "ready" dependent #30460
Comments
This has been the case since forever, it's not a bug. The rule is, properties of a node with |
So, basically, the rule is = don't use |
Wouldn't this work in that case?
|
@KoBeWi |
Ah, right. An ugly hack would be adding a Timer node and waiting for a very short timeout, but I doubt you'd need to do this THAT much. |
@KoBeWi won't work either because |
Exactly what happened. |
|
Yeah, but it will work AFTER it's added to tree. The idea is basically to wait until everything is set up. EDIT:
|
This breaks the idea of the setter, since it is meant to keep both nodes in sync whenever one changed the other should change as well, not only when one is ready. I think that what I can do is to instead of setting this directly, connect a signal and emit this signal when this Basically my script is:
So in my specific case I think I can connect the |
There is the
|
I usually do this in my scripts like so: export var x = 5 setget set_x
func _ready():
set_x(x)
func set_x(new_x):
x = new_x
if is_inside_tree():
# do something, like:
$sprite.frame = x Note that #6491 will help remove a few lines of that boilerplate, even more if it is made to work with |
For this I figured I should update such properties deferred most of the time: extends Node
export (NodePath) var node_path = ".."
onready var node = get_node(node_path)
export (bool) var enabled = true setget set_enabled
func set_enabled(enable):
enabled = enable
call_deferred('_update_properties') # updated on idle (next) frame
func _update_properties():
node.set_process(enabled) The above mechanism may cause extends Node
export (NodePath) var node_path = ".."
onready var node = get_node(node_path)
export (bool) var enabled = true setget set_enabled
var _update_queued = false
func set_enabled(enable):
enabled = enable
_queue_update()
func _update_properties():
node.set_process(enabled)
# might as well do more stuff
_update_queued = false
func _queue_update():
if not is_inside_tree():
return
if _update_queued:
return
_update_queued = true
call_deferred("_update_properties") |
What I always do is
This will delay the setters instead of returning and not setting anything at all. |
Seems like this isn't a bug, just a general misunderstanding that is quite logical and the engine provides tools to achieve the desired behaviors quite simply. I'll close it. |
Warning: Doesn't work right in tool scripts, as 'ready' is... off. I was just playing around with this in a tool
extends Control
onready var crect := $ColorRect2
export var crect_color :Color = Color.green setget set_crect_color
func set_crect_color( value :Color ):
crect_color = value
print("pre check")
print(get_signal_connection_list('ready'))
if not is_inside_tree(): yield(self, 'ready')
print("post check")
print(get_signal_connection_list('ready'))
crect.color = value Put that on a Edit: This may be related to the fact that the script is erroring out. Seems like if I change Edit Edit: Looks like it's only an issue cuz the tool script keeps the old object around if there's an error. As soon as you clear up the error, the old obj is deleted and the leaked signals along with it... pretty sure. As for the onready vars, that's more this issue: #16974 |
Two simple workarounds: godotengine/godot-proposals#325 (comment) |
Godot version: 3.1.6
OS/device including version: Solus Gnome 4.0
Issue description:
Alright, this sounds kinda complex, but the issue is simple, so I'll give context first.
I have this script:
The thing is, if I change the
Enabled
value in the inspector, theset_enabled
method crashes when running the scene, because seems like the method is called before the_ready
callback, or at least before theonready
variable being set. So it reports thatnode
is null, therefore it is unabled to callset_process
.I think that this could be fixed by changing the order in which
setget
methods are called, making them wait foridle
process at least?Steps to reproduce:
Enabled
to falseThe text was updated successfully, but these errors were encountered: