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()

func _physics_process(delta):

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):

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):


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



class_name WeaponBase

extends Node2D

func Rotate_Weapon():

the intermeditate

class_name SwordBase

extends WeaponBase

func Rotate_Weapon():

the a_sword.gd :

extends SwordBase

var Sword

func _ready():

func _physics_process(delta):

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.