This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
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?

in Engine by (73 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

2 Answers

+2 votes
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.

by (29,510 points)
selected by

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

0 votes

Try using the onready keyword?

by (65 points)
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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.