Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Twk Amz | |
Old Version | Published before Godot 3 was released. |
Hi, I’m trying to make a RigidBody2D which I can resize from the editor. I exported a variable called size, and defined a getter and a setter for it. When I change the size variable(as rigidbodies cannot be scaled), I want to scale all the children of my rigidbody. The thing is, inside the setter I cannot access the children of the node.
This is what happens:
extends RigidBody2D
export var SIZE = Vector2(64, 64) setget setSize, getSize; # my exported var
func _ready():
pass
func setSize(newSize):
print(get_child_count()) # outputs 0
#[Lots of crazy resizing here]
func getSize():
return SIZE;
If i try to access the children nodes from another method, it’s ok, but in the setter it’s impossible. Any ideas why?
Thanks!
EDIT: Ok, I found that this is happening because the setter is being executed before the children nodes are loaded. If I use live editing and change the scene after running the games, it works(because all nodes are loaded). How can I “wait” for the children to be loaded before executing the setter? Or is there a better way to do it?