Need help with reflection in GD Script

Godot Version

4.61

I want to do a plugin to generate c# code for signals based on the selected node in the scene tree.

Originally I was looking to try and use the existing signal tab, but couldn’t find a way to do it without looking up the signals tab, and that seemed clunky.

So I decided to make a dock plugin and just duplicate the current signals tab, allowing me to do the same thing. However I seem to have hit a wall and am hoping one of the script gurus here can help me figure out the logic or point out an easier way to do it. In the signal tab it presents the signals grouped under base object, I already have the tree set up and it loads signals, but how would I determine which group a signal belonged to, in order to group them together?

I currently use get_signal_list() to get the signals and then parse the dictionaries to create the tree but I nothing pops out at me as to indicating the base object the signal is from.

Also it is possible to get the default icon for that group?

Here’s a screenshot to help clarify. The signal tab is on the left, my tree on the right. Any advice would be appreciated.

1 Like

Reinventing the wheel again, eh? :wink:

Use ClassDB::class_get_signal_list(). Iterate up or down the inheritance chain and query for each class.

As for icons, you can get the editor theme via EditorInterface::get_editor_theme(), then call get_icon() on it. The first argument should be the class name and the second "EditorIcons"

2 Likes

Thanks.

Only sort of reinventing the wheel, the current signals tab doesn’t generate any C# code so connecting a signal there doesn’t really do anything other then reference it in the scene file.

I had hoped there was a way to just add some functionality to the existing tab, but could find no good way to do so.

I’m trying to enhance the editor a bit so I can do some things in C# without wanting to scream.

Afaik is should create an empty function in the script source if it doesn’t already exist.

Not sure what you meant by creating the script function.

Took a break for lunch and tried your advice and it worked wonderfully. Thanks a lot.

I wish ClassDB could handle script-defined classes.