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

hopefully this works with your nodes. from Godot Editor → Editor (menu) → Manage Editor Features. Then create and name a profile. Scroll down to the Nodes and Classes section.

https://www.reddit.com/r/godot/comments/mkqvol/how_do_i_remove_certain_nodes_from_the_create_new/

1 Like

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

1 Like

try this:

void set_disable_class ( StringName class_name, bool disable )

If disable is true, disables the class specified by class_name. When disabled, the class won’t appear in the Create New Node dialog.

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

well, i created a plugin that ran my EditorFeatureProfile script. still no joy. that sucks, sorry my friend

#does not work
extends EditorFeatureProfile
func _init():
	print("editor feature")
	set_disable_class("MyClass2D", true)
#does not work
@tool
extends EditorPlugin

func _enter_tree():
	print("running plugin");
	load("res://MyEditorFeatureProfile.gd").new()

func _exit_tree():
	pass

1 Like

tagging @pennyloafers and @mrcdk because they seem to know everything about Godot.

edit: almost 6am. I better get to bed

Thank you and good night!

@shrooms 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.

3 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.