0 votes

Hello all,

I am working in a project with Godot. The thing is that I have three scenes that are very similar between them. Basically, they have the same node structure, and mostly the same content in the scripts. So I decided to create a class: particle_class.gd, which extends RigidBody.

Then, the three scenes (which are RigidBodies) have a script attached, that extends particle_class.gd. Until this point, everything is fine.

But now, I want to make an instance of the children scenes. Then, inside particle_class.gd, I have something like:

var particle = preload("../scenes/free_particle.tscn")

func do_things():
    var aux = particle.instance()
    add_child(aux)

When I try to compile this, I get this cyclic preload error:

Parser Error: Script not fully loaded (cyclic preload?): res://scripts/particle_class.gd

I imagine that this is coming from the fact that when I load free_particle.tscn, this tries to extends particle_class.gd, which iteratively tries to load again the free_particle scene.

My question is: how to avoid the cyclic preload error?

asked Aug 30, 2017 in Engine by VictorSeven (67 points)

I get the same when extending another script - but only if the other script has an error.
Check your script to see if this could be the possible solution.
The other fix I believe has something to do with class names and a engine bug ... in 3.1 I believe

1 Answer

+1 vote
Best answer

In an object-oriented thinking, I would not try to load specialized objects from within a base object. But if you really want to do this, you can try to use load instead of preload. The difference is, load will run after assets are loaded.

answered Aug 30, 2017 by Zylann (26,143 points)
selected Aug 31, 2017 by VictorSeven

That works, thank you. In any case, I would like to know what are the alternatives to calling childs from base objects... sending a signal and catching it elsewhere or something like that?

Why do you need these in the base class in the first place? If it's about spawning "particles" in your case, you can either have a particle spawner script that does this. Or you can assign the specialized particle scenes as an exported variable on scenes that need to spawn them.

Well, I did it that way basically the particle desintegrates. Then, I think that it is logical that "particle_class.gd" includes a method that does the desintegration, spawning more particles.
I don't think that the exported variable is a good idea. I need to assign the instance beforehand, but in that moment I don't know how many particles I will instantiate. Moreover, they will be deleted after...

I still think there is a way to not have this cyclic coupling though, but I might miss the big picture here :)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.