diff --git a/modules/openxr/editor/openxr_editor_plugin.cpp b/modules/openxr/editor/openxr_editor_plugin.cpp index 353b55c4a9a..0e053881ef7 100644 --- a/modules/openxr/editor/openxr_editor_plugin.cpp +++ b/modules/openxr/editor/openxr_editor_plugin.cpp @@ -31,6 +31,7 @@ #include "openxr_editor_plugin.h" #include "../action_map/openxr_action_map.h" +#include "../openxr_api.h" #include "editor/editor_node.h" #include "editor/gui/editor_bottom_panel.h" @@ -47,9 +48,12 @@ bool OpenXRExportPlugin::supports_platform(const Ref &p_ex } bool OpenXRExportPlugin::is_openxr_mode() const { + // Check if OpenXR is enabled using `EditorExportPlatform::get_project_settings()` because that'll + // take into account the feature tags on the specific export preset that is being exported. + bool openxr_enabled = (bool)get_export_platform()->get_project_setting(get_export_preset(), "xr/openxr/enabled"); int xr_mode_index = get_option("xr_features/xr_mode"); - return xr_mode_index == XR_MODE_OPENXR; + return openxr_enabled && xr_mode_index == XR_MODE_OPENXR; } String OpenXRExportPlugin::_get_export_option_warning(const Ref &p_export_platform, const String &p_option_name) const { @@ -150,7 +154,7 @@ String OpenXRExportPlugin::get_android_manifest_activity_element_contents(const // OpenXREditorPlugin void OpenXREditorPlugin::edit(Object *p_node) { - if (Object::cast_to(p_node)) { + if (action_map_editor && Object::cast_to(p_node)) { String path = Object::cast_to(p_node)->get_path(); if (path.is_resource_file()) { action_map_editor->open_action_map(path); @@ -159,23 +163,29 @@ void OpenXREditorPlugin::edit(Object *p_node) { } bool OpenXREditorPlugin::handles(Object *p_node) const { - return (Object::cast_to(p_node) != nullptr); + if (action_map_editor) { + return (Object::cast_to(p_node) != nullptr); + } + return false; } void OpenXREditorPlugin::make_visible(bool p_visible) { } OpenXREditorPlugin::OpenXREditorPlugin() { - action_map_editor = memnew(OpenXRActionMapEditor); - EditorNode::get_bottom_panel()->add_item(TTRC("OpenXR Action Map"), action_map_editor, ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_openxr_action_map_bottom_panel", TTRC("Toggle OpenXR Action Map Bottom Panel"))); + // Only add our OpenXR action map editor if OpenXR is enabled for the whole project. + if (OpenXRAPI::openxr_is_enabled(false)) { + action_map_editor = memnew(OpenXRActionMapEditor); + EditorNode::get_bottom_panel()->add_item(TTRC("OpenXR Action Map"), action_map_editor, ED_SHORTCUT_AND_COMMAND("bottom_panels/toggle_openxr_action_map_bottom_panel", TTRC("Toggle OpenXR Action Map Bottom Panel"))); - binding_modifier_inspector_plugin = Ref(memnew(EditorInspectorPluginBindingModifier)); - EditorInspector::add_inspector_plugin(binding_modifier_inspector_plugin); + binding_modifier_inspector_plugin = Ref(memnew(EditorInspectorPluginBindingModifier)); + EditorInspector::add_inspector_plugin(binding_modifier_inspector_plugin); #ifndef ANDROID_ENABLED - select_runtime = memnew(OpenXRSelectRuntime); - add_control_to_container(CONTAINER_TOOLBAR, select_runtime); + select_runtime = memnew(OpenXRSelectRuntime); + add_control_to_container(CONTAINER_TOOLBAR, select_runtime); #endif + } } void OpenXREditorPlugin::_notification(int p_what) { diff --git a/modules/openxr/register_types.cpp b/modules/openxr/register_types.cpp index 6d65b391e40..0b02b778000 100644 --- a/modules/openxr/register_types.cpp +++ b/modules/openxr/register_types.cpp @@ -109,17 +109,15 @@ static Ref openxr_interface; #ifdef TOOLS_ENABLED static void _editor_init() { if (OpenXRAPI::openxr_is_enabled(false)) { - // Only add our OpenXR action map editor if OpenXR is enabled for our project - if (openxr_interaction_profile_metadata == nullptr) { // If we didn't initialize our actionmap metadata at startup, we initialize it now. openxr_interaction_profile_metadata = memnew(OpenXRInteractionProfileMetadata); ERR_FAIL_NULL(openxr_interaction_profile_metadata); } - - OpenXREditorPlugin *openxr_plugin = memnew(OpenXREditorPlugin()); - EditorNode::get_singleton()->add_editor_plugin(openxr_plugin); } + + OpenXREditorPlugin *openxr_plugin = memnew(OpenXREditorPlugin()); + EditorNode::get_singleton()->add_editor_plugin(openxr_plugin); } #endif