Godot Version
4.3
Question
I have a problem with an extended script of a class that has an update function in the physics process to which when I add something in the extended script I overwrite the entire function deleting the update function. How could I add things in the physics process without removing what was written in the class? P.S. This forum was written with Google Translate and may be translated incorrectly.
Could you post a code example?
Just call super() in the inherited physics class:
func _physics_process(delta: float) -> void:
super(delta)
#do your new stuff
Class script
extends Node
class_name SkillClass
var level = 1
@onready var subject : CharacterBody2D = get_parent()
@onready var data = subject.get_skill_data()
@export var texture_icon : CompressedTexture2D
var air_inertia = 0
signal active
func reach_speed(value : int):
if subject.velocity.x >= value:
return true
func heavy_landing():
if not subject.is_on_floor():
air_inertia = subject.velocity.y
return false
elif air_inertia >= 450:
air_inertia = 0
return true
func _physics_process(delta):
data = subject.get_skill_data()
extended script:
extends Skill_Class
func physics_process(delta):
anything
ok thanks but aint another way to do it without call super?
Nope.
Calling a method without super() is overriding the method. Calling a method with super() is extending the method.
Is there a reason that won’t work for you?
No, it does work, I just wanted to know if I could avoid writing super() every time I extend the physics process