godot-python icon indicating copy to clipboard operation
godot-python copied to clipboard

Extend Script does not work

Open vskovzgird opened this issue 4 years ago • 1 comments

I am trying to apply inheritance for my project.

I have res://scripts/__init__.py and res://scripts/NPCMovement.py. Next, I create new inherited scene, and click Extend script. The new script will be stored as res://scripts/EnemyMovement.py

For instance, NPCMovement.py has a class and a method:


@exposed
class NPCMovement(KinematicBody2D):

	def _physics_process(self, delta):
		self.update()
		self.aim()

which I try to redefine in EnemyMovement.py like this:

from godot import exposed, export
from godot import *
from scripts import NPCMovement as npc

@exposed
class EnemyBase(npc.NPCMovement):
	def _physics_process(self, delta):
		print('NEW PHYSICS PROCESS APPLIED!!!')

But no matter what method I am trying to re-define, nothing happens. It still call original methods from NPCMovement.py class.

vskovzgird avatar Oct 12 '21 06:10 vskovzgird

Just did some testing - even removing the parent script entirely in the child scene will not prevent methods in that script from running. It seems as if Godot forces the parent script to run as well, besides the child script. Testing further with gdscript shows that this doesn't happen there.

CombustibleLemonade avatar Aug 19 '22 13:08 CombustibleLemonade