-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for registering global script classes (class_name) using C# #26875
Comments
Where do |
Just functions I added to a script, again, I don't know if this is the right way so let me rephrase it. Is there a way to use the class_name functionality of GDScript in C#? |
No, I will add that after 3.1 (it's too late to risk introducing regressions). I still don't understand were those methods come from though. I can't find any |
They were just trying a shot in the dark I think, to see if by chance those would have been the virtual methods used to expose this feature. In GDScript, the syntax is: extends Node
class_name MyNode
# or, with icon:
class_name MyNode, "res://path/to/icon.png" |
It's implemented in gdscript_parser.cpp. Look for |
C# classes don't appear as a node type in add node dialogue, which is the main use case of class_name keyword. |
Ah that explains that then. Lots of different ways of solving this though. |
It would be |
Only if you use fully qualified names. Is the class name supposed to be used only for display purposes or is that actually stored somewhere? |
I think the class name is for display only. The script is actually referenced with the path, since that's how Godot does scripts. |
The class name is also registered as a global class. You can do |
Hm so that means you won't likely be able to use the fully qualified class name since periods in the name would break it? |
I'm pretty sure the Also the |
Since Godot already has another way to create custom node types which works with any language, and since
See: #16863 (comment). For the different functionality idea, we could have it be classified as a different type when compared using Another idea, it would be useful if we could create custom structs in GDScript, we could use |
I don't think those are the same. AFAIK, class_name can be used with ordinary scripts which are part of a plugin. class_name is very useful because not every custom type needs to be a plugin, so please don't deprecate it. |
Iirc, the GDScriptLanguage class has a Vector that it uses to store a collection of global variables for the language and a string->int map (can't recall if HashMap or Map) that registers the script class names to the corresponding indexes. During its initialization, it runs through the list of types defined in the ScriptServer, loads all of the file paths, and adds them all as global variables. So, if you had a FQN stored as the script class name in the ScriptServer, it would likely just end up creating a global variable that couldn't be accessed (since no valid GDScript identifier would match the string key in the map that provides the corresponding global variable vector index). The CSharpScripts would get turned into inaccessible globals.
That sounds more like the
Actually, the main difference is that script class names can be accessed at runtime while custom types can only be accessed from the editor. Furthermore, in order to define a custom type, you must register it via an EditorPlugin whereas script classes are defined directly from the script's file. The EditorFileSystem that scans the project every time you save in the ScriptEditor will also attempt to update script class names. It iterates over all script files, figures out which ScriptLanguage instance to grab, and then calls Rather than deprecating the highly specific script classes in favor of the generic custom types, the better approach would be to add support for script classes to all scripting languages and then completely deprecate the custom type system since it doesn't support as wide of a feature set. GDScript and NativeScript already have support (although NativeScript doesn't generate any global variables or anything). The only reason I didn't add support to CSharpScript initially was because you needed the I haven't added support to VisualScript cause, at the time, I would've needed to define a GUI and I was running out of time since the 3.1 release was so close. And I just haven't come back to the problem yet. All you have to do to add support is grant some way for a Script to define a class name and/or icon, and then have the ScriptLanguage implementation return that data when |
While I would love to see this done as part of godotengine/godot-proposals#22, there's no way that this is going to be done for 3.2. I suggest bumping to the 4.0 milestone. |
@aaronfranke Yeah, this won't be done till 4.0 at the earliest. In fact, I already have a partial implementation done, but I am having trouble getting the ScriptClass attribute detected by the CSharpScript. Waiting to hear back from @neikeq for assistance on figuring out why my code isn't working. |
Does the milestone still checks out or this will be postponed for 4.1 or other future version? |
Godot version:
3.1rc1
OS/device including version:
Linux
Issue description:
Class name and icon features don't seem to be working with C#/Mono.
Steps to reproduce:
I tried adding functions GetClassName() and GetScriptClassIconPath() to a C# script but didn't work (is this how it's supposed to work?).
Minimal reproduction project:
The text was updated successfully, but these errors were encountered: