This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Is there a way to define a class property with some sort of "onready" functionality, similar to how it's done in gdscript? Could it be something similar to how exports are defined? ( I haven't been able to see any mention of this anywhere.

Something like this maybe?

public class Game : Node
    public Sprite sprite = GetNode("Sprite");
in Engine by (1,663 points)

1 Answer

0 votes

just do it in the _Ready() function?

public Sprite sprite;
public override void _Ready()
    sprite = GetNode<Sprite>("Sprite");
by (220 points)

Thanks for the response. I'm aware of that approach, but was hoping there was something a little more terse available.

They could build a Attribute system to do what you want,

The problem is it's a lot of work, and pretty bad performance, and (arguably) makes your code harder to read. So very much not surprised this isn't supported.

thanks I came here looking for onready var timer: Timer = $Timer alternative in C#.

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.