-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Split class_name responsibility into two keywords #4493
Comments
I wanted to separate the problem from my opinion, this post will be mostly about my point of view, and what I personally see as an ideal solution, and where I come from (we don't need to discuss that part, just wanted to give a chance to understand my point of view a little better): So I would even go as far as merging 2 and 3 into one, and only allow to register scenes in add new node window, let me explain. (2 is Ability to register script to be part of 'add new node' window 3 is Ability to register a scene to be part of 'add new node window') When writing any game various systems will have tendency to grow and became more complex. Let's say I wrote a script that represents a prop in the game world. Level designer used it in 12 levels dozens of time in each level. Now it turns out that we need to add whole new subsystem to the prop, the only way we have to do it is to do it from script, even if given subsystem is very complex and having it as a configurable at editor time makes a lot of sense. Not to mention it's quite normal during development cycle for any given system to continue growing and became more complex. Having ability to just separate systems into well encapsulated subscenes is simply helpful to be able to understand the relations between subsystems quicker. But it's too late, since that decision need to be taken early on: in this case the prop should have been a scene not a script. |
I agree. I feel discouraged to use class_name exactly because of the polution of classes that gets added to the "Add Node" menu. |
In godot 4 we could use class_name for point1 and class_name specific annotations for points 2 and 3 |
Instead of two keywords, it would make sense for the editor behavior to be an annotation. I would do something like this: # Visible in the editor and usable as a class in GDScript.
@editor
class_name MyClass
extends Node
# Not visible in the editor, still usable as a class in GDScript.
class_name MyClass
extends Node
# Bonus idea, optional: Visible in the editor, but not usable as a class in GDScript.
@editor
extends Node |
#1909, seems to deal with 'script <-> scene pair' part of the proposal in a more complete way |
doesn't so rather than introducing new keywords or annotations (btw
I think this would only make sense as a possible feature of built-in scripts. Or how else would you bind a script to a particular scene? edit: Ah, just saw the other proposal you linked, guess that takes care of that. |
I think it's proven at this point that functions with lots of undescriptive arguments prove hard to maintain and read. I suppose that'd be the same case, here. The |
Perhaps,,, extends Node
class_name MyClass
@editor_scene_tree_instantiable |
I support @aaronfranke's approach to this, but I don't think that an @editor annotation without |
the current behavior should be the default though. not wanting certain node classes to be instantiable from the create new node modal is likely much less common, so that's when the extra annotation should be needed - not the other way around. that would also be more beginner friendly, as users learn about the ability to have their custom node classes appear in the create new node modal by stumbling across it rather than having to read up on a special annotation. also, rather than completely hiding nodes, it would probably make more sense to instead utilize this existing feature: this way, the modal can still be used as a nice overview to browse the full inheritance tree, while at the same time not being "polluted" as these grayed out classes are not searchable. with that, it would no longer make sense for the annotation to be
that would be really cool, but seems out of scope for this proposal. |
I actually don't think it's "much less common" necessarily. The bigger a project is, the more likely it is you will have more people on your team and therefore the more likely it is you will want to be able to define types that you don't want to be easily accessible from the editor. And if we are going to have a compatibility-breaking change, this would be the time to do it.
This would mean allowing scripts to define uninstantiable, abstract classes. Godot Engine does not currently support this for Scripts (don't ask me why cause I don't quite understand it myself). Either way, the types would still be showing up in the hierarchy (it's still polluted because it's visible) and thus would become things that users may not want to have exposed at all. You wouldn't want people to start asking about these greyed out types when it will never be relevant to that team member in the first place.
If the examples/tutorials they learn from already include the "special annotation", then it will work the same way. Especially if...
I propose that we simply re-use the |
hm, I can't really think of any situation where it would be an actual problem for node classes to be listed in the modal. granted, I'm not working in a big team, but in my mind, when someone doesn't know what a thing is and does, then they're not going to touch it. as long it's not something that's in their way, it's generally not a problem. I would however have actual use for the ability not to hide, but to "disable" classes from being selectable. in this case, if the feature existed as I described it, I'd like to flag Actor and Combatant as non-selectable & grayed out.
ok, I haven't thought about that those classes are not only displayed in a special way in the modal, but also not instantiable in code - so that exact feature cannot be adapted for user classes. but all we care about is the display part. so I don't see any blocker in showing classes that are registered with a special annotation in this way.
hardly an issue when those classes are somewhere nested & collapsed, and again, they don't show up the moment you are filtering which is the only practical way to use the modal.
bold of you to assume that new users go through those :) |
If anything, I would just suggest that the default script template automatically add the |
Usually I don't want the script to be instantiable from the editor, but rather the scene. ProposalWill replace the create node item with a scene: (Note: This looks similar to godotengine/godot#21187) @editor_scene("res://game/player.tscn")
# relative paths would be awesome too - @editor_scene("player.tscn")
extends Node
class_name Player As proposed earlier, a class name can be hidden from the editor: @editor_hidden
extends Node
class_name SuperSecretNode |
Perhaps you are more thinking of my scene-binding proposal, #1935? If so, this would be a totally separate thing from whether or not the node is visible in the editor though. It forms a 1-to-1 relation between a script and a scene and makes instantiation of the script with If you believe that idea is a good approach, then I would prefer that you go and upvote that proposal as opposed to trying to mix that idea into this one (otherwise, this proposal is just trying to "propose" too many different things). From my understanding, the primary purpose of this proposal is to provide a means for users to clearly distinguish between a request for assigning a global name to a script file and a request to expose said globally named script file to the Godot Editor. As a matter of scale, I believe that exposure to the Editor should be an opt-in operation syntactically (even if a default template could add it out-of-the-box for scripts with class names to make it user-friendly), so I'm going to try and implement it with the I could then ideally / potentially follow it up with implementing |
If #5641 is implemented, it would help with many of the use cases here.
It hits several birds with a remarkably small stone (only about 50 lines of additions and nearly zero performance cost). |
I'm not sure if being able to instance scene which has abstract script is such a good idea. |
To give some examples, in most games I was working on there were couple the same abstractions like "Level" and "Enemy" which had quite significant node structures defined by scene but which could never be instanced directly. They always needed to have an inherited scene complementing the node structure and a script which was complementing the base logic. |
I'm with @kubecz3k on this. If there's an If you're looking to define a script that should only ever be integrated into a scene and never used for direct instantiation, then that should really be it's own entirely separate proposal. |
I would like this so that I can type name my scenes. This would mean I can define everything in a scene and when I pass the scene/node instance as a parameter I can use static typing |
Describe the project you are working on
TailQuest, other networked project involving bigger team of developers
Describe the problem or limitation you are having in your project
I would like to propose to separate the functionalities of class_name keyword.
Currently it's doing two distinct things that, from my experience very often should not happen at the same time:
The fact that it does the second point feels off for me. If I would write static typed game the 'add new node' window would be polluted with hundreds of entries which are not usable at all.
It's so for two reasons:
Describe the feature / enhancement and how it helps to overcome the problem or limitation
The ideal way to solve this would be to separate the functionality of class_name into couple distinct features:
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
If this enhancement will not be used often, can it be worked around with a few lines of script?
No
Is there a reason why this should be core and not an add-on in the asset library?
It's core
The text was updated successfully, but these errors were encountered: