Why am I getting this error: 'The class 'HexPlanet' couldn't be fully loaded (script error or cyclic dependency)'

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By abelgutierrez99

I understand what the error means, but I can 't see where is the problem.

So here is the main scene script:

extends Node


func _init():
	var hexPlanet : HexPlanet = HexPlanet.new() # here is the error
	add_child(hexPlanet)
	
	var balls = preload("res://Assets/Auxiliar/Balls.tscn").instance()
	add_child(balls)
	
	var camera = preload("res://Assets/Cameras/CameraGimbal/CameraGimbal.tscn").instance()
	add_child(camera)

The HexPlanet script:

class_name HexPlanet
extends Spatial


var R : int = 10
var rng : RandomNumberGenerator = RandomNumberGenerator.new()
var tilesVpositions : PoolVector2Array


func _ready():
	
	rng.randomize()
	
	tilesVpositions = GLOBALS.hex_circle(Vector2.ZERO, R)
	
	var tile : Tile
	for i in range(tilesVpositions.size()):
		tile = Tile.new(tilesVpositions[i])
		#tile.change_center(MATERIALS.WHITE)
		add_child(tile, true)

GLOBALS is an autoload and Tile is another class I created, but didn’t give me errors in the past (all pieces of code work separately). The game is executed and the result is correct, but I get the error The class 'HexPlanet' couldn't be fully loaded (script error or cyclic dependency) I need to solve this to go further in my project.

Thanks!

:bust_in_silhouette: Reply From: Inces

I have never seen this manner of introducing variable. Do You have to assign type as your HexPlanetclass right before You assign value as new script of it ?

Try without it, like :

var hexPlanet = HexPlanet.new()

So this morning I opened Godot, I executed the game and the problem vanished without changing nothing XD. Can you explain me why?

abelgutierrez99 | 2021-04-12 07:39