Skip to content
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

Error exporting a Mono project with an editor plugin #51784

Closed
git2013vb opened this issue Aug 17, 2021 · 6 comments
Closed

Error exporting a Mono project with an editor plugin #51784

git2013vb opened this issue Aug 17, 2021 · 6 comments

Comments

@git2013vb
Copy link

git2013vb commented Aug 17, 2021

Godot version

3.4.beta3 mono

System information

debian 10

Issue description

When I try to export I have this error

addons/editorsettings/plugin.cs(5,23): The type or namespace name 'EditorPlugin' could not be found (are you missing a using directive or an assembly reference?)

the error screenshot:
image

While i can compile and run it without problems.
Here other errors in console:
addons/editorsettings/plugin.cs(10,26): 'plugin._Ready()': no suitable method found to override
addons/editorsettings/plugin.cs(18,26): 'plugin.EnablePlugin()': no suitable method found to override

Steps to reproduce

this is my plugin:

using Godot;
using DesertEdge.Utils;

[Tool]
public class plugin : EditorPlugin
{
    private const string PORT = "7010";
    private const string REMOTE_PORT = "network/debug/remote_port";

    public override void _Ready()
    {
        Log.Print(Log.DEBUG, "Plugin Editor Settings ready");
        EditorSettings editorSettings = this.GetEditorInterface().GetEditorSettings();
        editorSettings.Set(REMOTE_PORT, PORT);
        Log.Print(Log.DEBUG, editorSettings.Get(REMOTE_PORT));
    }

    public override void EnablePlugin()
    {
        EditorSettings editorSettings = this.GetEditorInterface().GetEditorSettings();
        Log.Print(Log.DEBUG, editorSettings.Get(REMOTE_PORT));
        editorSettings.Set(REMOTE_PORT, PORT);
    }
}

Minimal reproduction project

na

@YuriSizov YuriSizov changed the title Error exporting into linux Error exporting a Mono project with an editor plugin Aug 17, 2021
@Atlinx
Copy link
Contributor

Atlinx commented Aug 17, 2021

I think EditorPlugins are only supposed to run in the editor. GDScript plugins also have this behavior, which leads me to believe that this is intentional.

@raulsntos
Copy link
Member

Yes, access to the editor API must be surrounded with #if TOOLS as explained in #41196

@git2013vb
Copy link
Author

git2013vb commented Aug 18, 2021

I think EditorPlugins are only supposed to run in the editor. GDScript plugins also have this behavior, which leads me to believe that this is intentional.

It make sense ofc.. But still sometime a EditorPlugin is necessary to run. In my case I use to export the current project and run it outside editor in order to make free some hw resources while working in connected projects. Otherwise I have to pretend the project is finished and run it somewhere else. If I'm not mistaken there was an issue/discussion where mentioned the editor log port to be related to the project and not to the game engine.

@Atlinx
Copy link
Contributor

Atlinx commented Aug 18, 2021

I'm not really sure what you mean by "hw resources" and "editor log ports" but I normally keep my plugin logic out of editor-related classes such as EditorPlugin. Instead, my EditorPlugin class contains instances of classes that control the plugin logic. I can then just use those classes directly outside of the editor as well. Maybe you could try something similar to get your plugin working in standalone builds?

@git2013vb
Copy link
Author

I'm not really sure what you mean by "hw resources" and "editor log ports" but I normally keep my plugin logic out of editor-related classes such as EditorPlugin. Instead, my EditorPlugin class contains instances of classes that control the plugin logic. I can then just use those classes directly outside of the editor as well. Maybe you could try something similar to get your plugin working in standalone builds?

For "hw" I mean "hardware" :).. and for "editor log ports" I mean this one (from code before posted) :private const string REMOTE_PORT = "network/debug/remote_port";
See #37687 and godotengine/godot-proposals#578
How can your suggestion fit my problem?
Thanks :)

@raulsntos
Copy link
Member

raulsntos commented Jul 29, 2024

Closing as working as intended. Godot's Editor APIs (such as the EditorPlugin type) are not available in exported projects since there's no Editor.

Access to Editor APIs must be surrounded with #if TOOLS to prevent build errors when exporting the game, like so:

#if TOOLS
using Godot;

[Tool]
public class SomeEditorPlugin : EditorPlugin
{
	// Code here...
}
#endif

The use of the define constant TOOLS can be seen in the documentation for making plugins (in the C# code example).

@raulsntos raulsntos closed this as not planned Won't fix, can't repro, duplicate, stale Jul 29, 2024
@raulsntos raulsntos added archived and removed bug labels Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants