参数“ p_control”从容器中删除按钮时,无效错误是错误的吗

发布于 2025-01-25 09:08:04 字数 660 浏览 2 评论 0原文

我正在尝试创建一个插件,并在这样的顶部容器中添加一个按钮:

tool
extends EditorPlugin

var Btn

func _enter_tree():
    Btn=Button.new();
    Btn.name="Testing_btn"
    Btn.text="Testing";
    Btn.flat=true;
    add_control_to_container(CONTAINER_CANVAS_EDITOR_MENU,Btn);

func _exit_tree():
    remove_control_from_container(CONTAINER_CANVAS_EDITOR_MENU,Btn)

但是每当我更改代码时 - >保存 - >取消选中启用

它给出了错误:

editor/editor_plugin.cpp:458-参数“ p_control”为nuls。

I'm trying to create a plugin and add a button to the top container like this:

tool
extends EditorPlugin

var Btn

func _enter_tree():
    Btn=Button.new();
    Btn.name="Testing_btn"
    Btn.text="Testing";
    Btn.flat=true;
    add_control_to_container(CONTAINER_CANVAS_EDITOR_MENU,Btn);

func _exit_tree():
    remove_control_from_container(CONTAINER_CANVAS_EDITOR_MENU,Btn)

but whenever I make changes to the code -> save -> uncheck enabled
enter image description here

it gives the error:

editor/editor_plugin.cpp:458 - Parameter "p_control" is null.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终弃我 2025-02-01 09:08:04

看来,在remove_control_from_container运行之前,该按钮已被释放或无效。

我相信您可以通过检查is_instance_valid来避免错误:

func _exit_tree():
    if is_instance_valid(Btn):
        remove_control_from_container(CONTAINER_CANVAS_EDITOR_MENU,Btn)

It appears that the button is being freed or otherwise invalidated before remove_control_from_container runs.

I believe you can avoid the error by checking with is_instance_valid:

func _exit_tree():
    if is_instance_valid(Btn):
        remove_control_from_container(CONTAINER_CANVAS_EDITOR_MENU,Btn)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文