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? (https://docs.godotengine.org/en/3.1/getting_started/scripting/c_sharp/c_sharp_differences.html#export-keyword) 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");
asked Jan 8 in Engine by Eric Ellingson (1,581 points)

1 Answer

+1 vote

just do it in the _Ready() function?

public Sprite sprite;
public override void _Ready()
    sprite = GetNode<Sprite>("Sprite");
answered Jan 8 by Jason Swearingen (213 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.

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 How to use this Q&A? before posting your first questions.