Skip to content

Commit 055ec90

Browse files
committed
GDScript: Add warning about overriding non-virtual native methods
1 parent ccae259 commit 055ec90

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tutorials/scripting/gdscript/gdscript_basics.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,22 @@ the function name with the attribute operator::
15351535
func dont_override():
15361536
return super.overriding() # This calls the method as defined in the base class.
15371537

1538+
.. warning::
1539+
1540+
One of the common misconceptions is trying to override *non-virtual* engine methods
1541+
such as ``get_class()``, ``queue_free()``, etc. This is not supported for technical reasons.
1542+
1543+
In Godot 3, you can *shadow* engine methods in GDScript, and it will work if you call this method in GDScript.
1544+
However, the engine will **not** execute your code if the method is called inside the engine on some event.
1545+
1546+
In Godot 4, even shadowing may not always work, as GDScript optimizes native method calls.
1547+
Therefore, we added the ``NATIVE_METHOD_OVERRIDE`` warning, which is treated as an error by default.
1548+
We strongly advise against disabling or ignoring the warning.
1549+
1550+
Note that this does not apply to virtual methods such as ``_ready()``, ``_process()`` and others
1551+
(marked with the ``virtual`` qualifier in the documentation and the names start with an underscore).
1552+
These methods are specifically for customizing engine behavior and can be overridden in GDScript.
1553+
Signals and notifications can also be useful for these purposes.
15381554

15391555
Class constructor
15401556
^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)