Skip to content

Commit 5dc2506

Browse files
authored
Merge pull request godotengine#7591 from dalexeev/gds-warn-override-non-virtual
2 parents 191a1a1 + 055ec90 commit 5dc2506

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
@@ -1637,6 +1637,22 @@ the function name with the attribute operator::
16371637
func dont_override():
16381638
return super.overriding() # This calls the method as defined in the base class.
16391639

1640+
.. warning::
1641+
1642+
One of the common misconceptions is trying to override *non-virtual* engine methods
1643+
such as ``get_class()``, ``queue_free()``, etc. This is not supported for technical reasons.
1644+
1645+
In Godot 3, you can *shadow* engine methods in GDScript, and it will work if you call this method in GDScript.
1646+
However, the engine will **not** execute your code if the method is called inside the engine on some event.
1647+
1648+
In Godot 4, even shadowing may not always work, as GDScript optimizes native method calls.
1649+
Therefore, we added the ``NATIVE_METHOD_OVERRIDE`` warning, which is treated as an error by default.
1650+
We strongly advise against disabling or ignoring the warning.
1651+
1652+
Note that this does not apply to virtual methods such as ``_ready()``, ``_process()`` and others
1653+
(marked with the ``virtual`` qualifier in the documentation and the names start with an underscore).
1654+
These methods are specifically for customizing engine behavior and can be overridden in GDScript.
1655+
Signals and notifications can also be useful for these purposes.
16401656

16411657
Class constructor
16421658
^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)