My Godot tool script produces "Attempt to call a method on a placeholder instance." in editor, game runs fine when executed

My Godot tool script produces "Attempt to call a method on a placeholder instance." in editor, game runs fine when executed

In my Godot project I have a UI panel that displays data derived from a Resource. To be able to see how it looks immediately in the editor, I tagged it with @tool. But I started seeing errors like this:

Invalid call. Nonexistent function ...

The errors came whenever I tried to call the members of a custom object I fished from the scene. I decided to try with a development version, and the error became this:

Invalid call. Nonexistent function ... Attempt to call a method on a placeholder instance.

What is going on?

Answer

I ran git blame on the line where the Attempt to call a method on a placeholder instance.-message was recently added. It led me to this commit Read more. The commit message says:

GDScript: Fix message when calling non-tool function in tool mode.

So the problem was that I was invoking code from a script without the @tool-attribute when running the tool script. (In my case, a member function on a child panel of the main panel.) I added the tool attribute to the child panel and the error went away. It seems the attribute needs to be applied transitively to all code invoked at editor time. I suppose that makes sense.

Enjoyed this article?

Check out more content on our blog or follow us on social media.

Browse more articles