-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Add ready property (boolean) to nodes #5537
Comments
It shouldn't be an actual property, I don't believe users should mess with it as if it is one. For these use-cases, I believe a Currently, in 3.x, one really common way to check for this is with a similar snippet of code: onready var my_sprite = $MySprite
export var my_texture setget set_my_texture # The property is set in the Scene.
func set_my_texture(new: Texture):
my_texture = new
if (not my_sprite and not is_inside_tree()):
yield(self, "ready")
my_sprite.texture = my_texture
This, however, is not infallible. Frankly, because this is the only major example I can think of, maybe |
@Mickeon I know that the code solution like above is what I have done in multiple projects with setters and getters. I'm used to checking for the node existing a lot of times in my setters when they are executed before ready. In my opinion, it just feels tedious to keep writing the same boilerplate ready code for each setter and I wish there was a better way of handling it. I was wishing for there to be a if not SPRITE_NODE:
yield(self, "ready")
if not LABEL_NODE:
yield(self, "ready")
if not PLAYER_NODE:
yield(self, "ready")
# etc... for the hundreds of setters that I use in every script. |
Indeed, with the getter that situation would be improved, already. In Godot 4 it'd look something like this which, as much as the engine avoids boilerplate code, feels reasonable in comparison: @export var my_texture: Texture2D:
set(new):
my_texture = new
if not is_ready():
await ready
sprite.texture = my_texture |
@Mickeon By adding a @export var my_texture: Texture2D:
ready set(new):
my_texture = new
if not is_ready():
await ready
sprite.texture = my_texture or maybe Well if 4.0 is coming around soon, I guess I would have to keep using boilerplate code in 3.x or move to 4.x though I'm not sure when 4.x is going to be stable enough? |
Related: #325 btw we can't have |
@KoBeWi # sprite setter
if (not sprite and not is_inside_tree()):
yield(self, "ready")
# player setter
if (not player and not is_inside_tree()):
yield(self, "ready")
# label setter
if (not label and not is_inside_tree()):
yield(self, "ready") We can shave of some time by doing this: # sprite setter
if not is_ready():
yield(self, "ready")
# player setter
if not is_ready():
yield(self, "ready")
# label setter
if not is_ready():
yield(self, "ready") Of course if your node is intended to leave and enter the tree at various points in your code, you can do this: # sprite setter
if not is_inside_tree():
return
if not is_ready():
yield(self, "ready")
# player setter
if not is_inside_tree():
return
if not is_ready():
yield(self, "ready")
# label setter
if not is_inside_tree():
return
if not is_ready():
yield(self, "ready") Again though #325 sounds like what I want.. |
Ah right, if you use
No need to do 2 checks. if not sprite:
yield(self, "ready") and if not is_ready():
yield(self, "ready") are pretty much the same thing, because
Yeah, it solves the same problem. It's simpler to use, but more complex to implement. |
|
Yes, closing as implemented. |
Describe the project you are working on
I'm working on an utility add-on for Godot called Quik. I'm on Godot version 3.5.1 so I'm not sure if what I want to do is possible with Godot's 4.0 await and lambdas.
One of the features I'm trying to add is allowing the user to wait for a node ready's state in a setter function, and if the node is already ready, then i allow it to continue through the code.
This is so that I can wait for nodes in setters by changing this code:
to
Describe the problem or limitation you are having in your project
There seems to be no easy way currently to know what's the ready state on a node without having the user to manually write on_ready properties in their nodes, or I would have to store every single node in an array and detect when it's ready signal was emitted. This can be very costly on code performance.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
The feature is to add a boolean property accessible in GDScript called
ready
. When the node is ready, theready
property is true, when it's not ready, then it's false. This overcomes having to make my utility script add every node on start-up, keep track of the ready states from their signals, and having to loop over a huge array, to make sure the node is ready. This is also so that the code can safely yield for a node's ready without having to make the mistake of having an infinite yield. This can reduce boilerplate and tediousness of checking for ready states on dynamic nodes too.Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Utilities script
User's script
If this enhancement will not be used often, can it be worked around with a few lines of script?
It could be possibly worked around with around 150 or 300 lines of code. However this can be costly for performance especially when you use a lot of setter and getters, and call any setter or getter a lot of times.
Is there a reason why this should be core and not an add-on in the asset library?
Because it's impossible to grab any node and know it's ready in a script without having to keep track of all the nodes in your project.
The text was updated successfully, but these errors were encountered: