How to mark a method to virtual? and some annotations questions

Godot Version



I have been finding a lot of solutions, no help.
I tried this to my code:

class_name MyNode extends Node

func my_method() -> void:

and in its child class:

class_name MyChildNode extends MyNode

func my_method() -> void:
	# some code here

yeah, it will do, but I also see this: @virtual which is added in front of identifier func.
Then I tried it:

@virtual func my_method() -> void:

nope, it errored:

Line ...:Unrecognized annotation: "@virtual".
Line ...:Annotation "@virtual" is not allowed in this level

what happened?!

You can’t mark a method virtual. It does not make sense. Virtual functions are a way to expose some functionality of the internals of the engine into the scripting side. If you are in the scripting side already it does not make sense.

Here’s more information about inheritance GDScript reference — Godot Engine (stable) documentation in English

1 Like

GDScript simply doesn’t have virtual methods/functions.

Thank you guys for answering