Unable to reference the "root" on the super super class function

Hello everyone,

I’m making a weapon system and trying to make it modular but when I wrote one of the functions and called from a normal script to a super class the super class function suddenly returns “null” on it’s variables

Here is the code:

The script:

extends Sword_Base

var Sword

func _ready():
	Sword = Sword_Base.new()
	Sword.Test()


func _physics_process(delta):
	Sword.Rotate_Weapon(self)

The super class:

extends Weapon_Base

class_name Sword_Base

The super super class:

extends Node2D

class_name Weapon_Base

@onready var Root = get_node("/root/World_Root")

func Rotate_Weapon(Weapon):
	print(Root)
	Weapon.look_at(get_global_mouse_position())

Tldr: the “Root” variable on the super super class returns nill even though I already defined it in a previous line

usually it’s class_name then extends, iirc

about this:

the world_root is a node in main world scene?

I believe this is optional but not sure honestly :sweat_smile:

Yes and it prints correctly if I run the super super script on it’s own

so the error is at

func _physics_process(delta):
	Sword.Rotate_Weapon(self)

?

No it’s on this line:

The error in question:
Invalid call. Nonexistent function '.get_global_mouse_position' in base 'Nil'

ok, so you dont need to send “self” as parameter there, just look_at will do

Edited it as you suggested and now this error appears:
Rotate_Weapon(): Paramter "get_viewport()" is null

weaponbase

weapon_base.gd

class_name WeaponBase

extends Node2D

func Rotate_Weapon():
	look_at(get_global_mouse_position())
	rotation+=PI/2

the intermeditate

class_name SwordBase

extends WeaponBase

func Rotate_Weapon():
	super.Rotate_Weapon()

the a_sword.gd :

extends SwordBase

var Sword

func _ready():
	pass


func _physics_process(delta):
	super.Rotate_Weapon()

oh there was a keyword for super lol I didn’t really know that :joy:, Thanks it works now

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.