Get a GDScript child object inside another object from C#

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By kakubei

Hello, I’m trying to convert a GDScript to C# equivalent. I’ve got an object that contains another object inside it and cannot access the second (child) object.

The GDScript code:

func _on_options(options):
	var button_template = $VBoxContainer/ButtonTemplate
	for option in options:
		var button = button_template.duplicate()
		button.text = option.line.text

I need to get the option.line.text property.

I’m trying to work with the Wol GDSCript from here:

I’vet got the Wol Node already in my C# file and can access it without errors.

According to these docs: Cross-language scripting — Godot Engine (stable) documentation in English

I would image I need to do something like this:

var line = option.Get("line") as Line;
var newText = line.Get("text");

Of course, the problem is that my C# file doesn’t know what a Line object is and that it should contain a text property.

How can I access it in this case?


:bust_in_silhouette: Reply From: juppi


can’t you just get the Line as Godot.Object?

var line = option.Get("line") as Godot.Object;
string text = line.Get("text");

Yes, after much faffing around, that’s exactly what I did. What was throwing me off was that line is already an object but not a Godot Object!


kakubei | 2022-04-09 12:39