How to exclude custom classes from the "Create new Node" menu?

Godot Version

4.3.dev4

Question

I use static typing in my project and I like to create reusable components.
When I want to add a component to an object, I often create a new node of my class instead of instantiating the scene by accident.

image

Is there a way to exclude custom nodes with class names from the “Create new Node dialog” so I can’t make this mistake anymore?

@tool
class_name VisionComponent 
extends Area2D

## don't add this class to the "create new node" menu

1 Like

That’s a great idea but unfortunatly my custom classes don’t appear in this menu…

1 Like

This looks promising, but where I do I need to call this function? I can’t find it in the docs and it’s not working with the _ready function.

func _ready() -> void:
	var feature_profile := EditorFeatureProfile.new()
	feature_profile.set_disable_class("VisionComponent", true)
1 Like

Thank you and good night!

@anon45973056 I think you have it. I guess the next logical step would be to assign it to the editor profile… But I don’t see a way to do that

I was going to say idk, but maybe to enhance the script call. You could make a static func _static_init(): Godot should call this automatically whenever your class is first used.

The other option would be to remove the class_name. But I assume you use that in script to create it or reference static variables?

I think the only drawback is that you may want to use in other scenes you just don’t want two in a single scene?

If that is the case I don’t see an easy way around it…

Maybe you could somehow default to a disabled state and you could utilize the visibility as an indication? So if you accidentally created a new one it would be disabled and hidden.

Maybe you could edit an existing one?

2 Likes

After some testing is possible to use the EditorFeatureProfile to disable custom classes but re-importing it is not exposed for scripting (as far as I can tell).

Thankfully the .profile files are just JSON files that you can edit and import manually.

For example:

{
	"disabled_classes": [
		"VerticalLabel"
	],
	"disabled_editors": [],
	"disabled_features": [],
	"disabled_properties": [],
	"type": "feature_profile"
}

This JSON disables a custom class called VerticalLabel.

Just add whatever classes you want to hide in the disabled_classes array, save the file as a .profile file, and import it in the Editor -> Manage Editor Features... dialog. The name of the file will be the name of the profile.

4 Likes

Thank you all very much. Creating a custom .profile works, though it is a bit cumbersome.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.