Godot Version
4.3.0-stable
Question
Is there a way for Godot to load global class from another .csproj?
For example:
- src
- B.csproj
- AGlobalClass.cs
- A.csproj
- project.godot
AGlobalClass.cs
is a subclass of Node
and has already used GlobalClass
as attribute.
A.csproj imported B.csproj and removed src
folder from compile.
But Godot won’t show the global class when I creating nodes.
Thanks for your help.
Moreus
August 18, 2024, 7:09am
2
You cannot, you can export other project to dll and include in csproj, I didn’t test if [GlobalClass] will show from dll. Other way is just copy your classes to new project.
1 Like
Yes, I already tested including dll, but it doesn’t work. Meanwhile I don’t think copy the classes is a good solution. Any other way please?
Moreus
August 18, 2024, 4:21pm
4
I checked the DLL, and this should work as a workaround.
After receiving your DLL, you can create some empty classes that will inherit from the classes in your DLL.
For example, if you have a DLL with the following code:
using Godot;
namespace MySpace;
[GlobalClass]
public partial class MyGlobalClass : Node
{
/*
Body
*/
}
You can import your class into your .csproj
file and create a new class to access the class from the DLL:
using Godot;
namespace MyGame;
[GlobalClass]
public partial class MyGlobalClass : MySpace.MyGlobalClass
{}
Now, you should be able to see your global class. I hope this is enough for you.
1 Like
Well, another problem happened. When I include an godot project’s dll into other project and do as above, the class is still cannot be created from the editor. The class is derived from Resource
.
Any ideas?
Moreus
August 20, 2024, 9:47am
7
Resources can be created only in file system. if resource is from dll you can make same trick like with global class.
eventually you can try make partial class with same name and namespace in another file.
I made a simple project to test this, uploaded at here
Looks like it doesn’t work for some reasons
Moreus
August 21, 2024, 8:56am
9
I tried and is problematic but not impossible:
i tried this
using Godot;
namespace ProjectB;
[GlobalClass]
public partial class NewScript : Resource{
[Export] private ProjectA.NewScript newScript = new();
}
new allow create resorce instead left null.
our newScript is in list
this how is look
we have access to resource from dll
but careful making just New Script in inspector connect wrong script
before “Save As…” your target resource you needed make unique
after “save” you have your custom resource with script attached from dll
from here depends what you needed.
I think you can make editor plugin to manage your custom resources.
in editor plugin you can add custom things in theory
Moreus
August 21, 2024, 10:01am
10
ok im back to this:
using Godot;
namespace ProjectB;
[GlobalClass]
public partial class NewScript : ProjectA.NewScript{
}
and my plug-in script:
#if TOOLS
using Godot;
[Tool]
public partial class Scripttest : EditorPlugin
{
public override void _EnterTree()
{
var script = GD.Load<Script>("res://NewScript.cs");
var icon = GD.Load<Texture2D>("res://icon.svg");
AddCustomType("MyType", "Resource", script, icon);
}
public override void _ExitTree()
{
RemoveCustomType("MyType");
}
}
#endif
not sure if we want use same name here " NewScript : ProjectA.NewScript " becouse godot I think dont realy like it
can be ignored but personalty I don’t like.
Here where you create pluginScript Project/Project Settings/Plugin
Thanks! I have last question: Can I load the ProjectB back to ProjectA? And the ProjectB’s resource can be loaded as ProjectA’s
Moreus
August 21, 2024, 2:16pm
12
Is possible, if name and location is the same you should be no problem, but if your change location or name you needed fix dependencies in editor
1 Like
system
Closed
September 20, 2024, 2:58pm
14
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.