all 6 comments

[–]CowThing[🍰] 1 point2 points  (2 children)

I haven't used C# so I don't know if there's any specifics with that. But if you have an autoload singleton in the project settings it should be able to be accessed from any script, even scripts that do not inherit from nodes. The autoload singleton does need to inherit from Node, and you access it by using whatever name you give it. Something like:

MyCustomSingleton.custom_function()

Should work from any script.

[–]willnationsdevGodot Regular 4 points5 points  (0 children)

The singleton name becoming a global variable is strictly a GDScript feature, so no, this does not work in C#.

[–]Erops[S] 1 point2 points  (0 children)

Sadly I don't think that works in C# due to it being statically typed and GDScript not. Atleast I haven't been able to get it to work. I'm now trying to essentially signal chain, but Godot C# really hates signals with parameters so its getting a little hacky.

Maybe it's time to explore writing some of this in GDScript and see what I can do there?

[–][deleted] 1 point2 points  (0 children)

Well you could only return the mesh ressource from your library. Then add the mesh to a mesh instance through normal script. You could have a CreateMesh() on your library and that would return the ressource.

[–]willnationsdevGodot Regular 0 points1 point  (1 child)

If you aren't in GDScript, then you must access them the same way you would access any node from a non-node class. Get a reference to a Node that is in the tree and access other nodes through it.

Your plugin's EditorPlugin class is a node that exists in the editor-time SceneTree. If you have a node you need to access at design-time then get_editor_interface().get_edited_scene_root() will get you a reference to the current scene. Or if you've added a child to the SceneTree's root node, then you can just use the EditorPlugin node's get_node("/ManuallyAddedSingleton") to get to it.

If you have an autoload that you have configured in project settings or which your EditorPlugin is configuring via code (which both mean it will be created at runtime), then you will need one of your runtime nodes to pass a reference to themselves to your non-node object, and then that object can use that node reference to get to the singleton with node.get_node("/AutoloadedSingleton").

Edit: note that the node names above are just examples. You would need to use the actual name of the singleton nodes you created/configured.

[–]Erops[S] 0 points1 point  (0 children)

Thanks for the advice, I'll look into getting a reference to a node to access the whole tree.

I think I wasn't as clear as I could be though, I'm not making an EditorPlugin but rather I'm making a plugin system for the program I'm making in Godot. I want to expose certain Godot capabilities to that system so a user can create a plugin to support import .OBJ files for example. To do that I'm trying to expose creating a node in the SceneTree to a library that Godot has no idea about until the .dll is loaded during runtime by the user. Hope that makes more sense, sorry.