Calling a method from an editor

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By sygi

I am iterating over a code and would like to have a quick way for clicking a button in the editor to run some function in a Node. Here’s the code I have:

@tool
@export var run_now: bool = false:
    set(value):
        my_func()
        

func my_func():
      ...
    

func _process(delta):
    if run_now:
        my_func()
        run_now = false

I can see the “run_now” button in the editor, but clicking it doesn’t lead to the function being called . Is there an easy way to call a function like this from within this node?

1 Like
:bust_in_silhouette: Reply From: zhyrin

This works for me:

@tool
extends Node

@export var button: bool = false : set = set_button

func set_button(new_value: bool) -> void:
    print("from tool")

It doesn’t for me, any idea what went wrong? Are you using the same version?

sygi | 2023-03-16 19:30

I figured it out. For “tool” to have the effect, you need to:

  1. save the script
  2. run the project
  3. change to a different scene and back

sounds like a bug in the editor to me

sygi | 2023-03-16 19:51

That has been how it is since 3.x at least. It’s even written in the docs.

zhyrin | 2023-03-16 20:09

1 Like