-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some usages of class_name
can produce cyclic errors unexpectedly
#21461
Comments
It'll work if you give the base script a class_name and use that in the extends line. |
@PetePete1984 Cool, thanks Pete. This is how it is intended to be used then? While double checking and testing this, I was looking at the |
I wouldn't say it's intended behaviour, especially not with an error message that implies cyclic inclusions where there aren't any. |
@vnen Would this be something that is in need of a clearer error message? @PetePete1984 Yes, |
@avencherus You might be able to get away with:
|
I'm not sure why it's giving this error, I'll have to investigate. |
@willnationsdev Not entirely sure what the check for from @vnen Thanks vnen. X) Some other weird things seem to be going on when I went back to try out these suggestions to see if I could give you some better information. I'm going to pull and rebuild and fiddle with it in a little bit. See if there is anything else about it to add. I may have bumped into a different issue as well along the way. |
@avencherus the "class names" of script classes are global variables that reference the script. So...
|
@willnationsdev Oh neat, I see now. I wasn't expecting class_name to work like that, or the custom type to be available to the match pattern . Thanks for sharing this tip Will. |
@vnen Yes, some additional wrinkles to the story. Let me see how well I can articulate them. Firstly, Pete's solution works, when a base class is given a Then to confirm this, I went to recreate the steps of creating a base2.gd -> custom2.gd extended script. Then inside custom.gd use Another issue appeared. The node list had the first one, but listed with an icon that said "Error" So I modified the first base class so they both used Not everything is showing up in the node list, and then the It seems like lot of things are getting switched up or are lingering about behind the scenes. Hard to quite predict what it may be doing with my limited knowledge. Hope that helps. X) |
@bfishman script classes are not a feature in 3.0.x. That is why it is not working. |
I just tried the following and each version worked. All script classes showed up in the CreateDialog, the scripts compiled fine, the scene ran successfully, etc. With a scene hierarchy like this:
Script:
Every time I ran the test, it printed
...as it should. My suggestion would be to try clearing your editor's file cache (if perhaps there were changes in the way the file cache was stored in the midst of your programming / updating the engine, that could somehow mess things up until you clear it away). |
@willnationsdev Thanks for looking at, I'll try this out. Is this the files from AppData/Roaming folder? I'll go ahead and clear the whole thing for now. If so, wondering if there is something more specific that I should delete? |
@avencherus I'm not quite sure. I just recall @karroffel mentioning something about it when I added some fixes to the script class icon stuff earlier. |
Tested on 1093c0f |
I'm also getting the error shown in the original post (Windows x64 Godot 3.1 alpha): However, it happens in a different context. I have 3 scripts which each have a different So there's a ClassA, ClassB, ClassC. If ClassC references ClassA with the None of the scripts are in the same scene, and all of the nodes are siblings (no ancestor relationship). |
@AlexHolly Same situation with me now as well. The error seems to be gone, but yes, classes won't appear in the add node window when not having a base script that also uses This is in alpha 3.1 c320d93 |
A small example by using "is". The same thing can happen if you use "as". |
This has nothing to do with the nodes in the scene. Cycles happens in the script themselves. For now it's quite easy to get cycles when using |
I couldn't reproduce the error in 451e5fd as well. The node didn't show up in the create window tho. |
I can confirm that this Issue is not present in 0dbe014 (the latest master I pulled). We can probably close this Issue. Also, I was able to make it so that the script classes that extend scripts still show up in the CreateDialog which was still a bug. PR is linked above. |
@willnationsdev Thanks Will. X) I have been bumping into various issues with I have noticed sometimes vague and unrelated errors can appear in a script, because of errors in a script that is being referenced. They become more meaningful when opening the culprit script, and when fixed these other ones clear out as well. I will re-tailor the topic of the post though, because this cyclic error does seem to still be happening in odd situations and is elusive when trying to recreate it. So there is probably still something to it, I'll leave it open for vnen. |
I would like to correct myself, this is still reproducible in 4.0. |
This will only be fixed in Godot 4.0? |
From the lead maintainers, unlikely to be backported to 3.x, since resources are allocated to 4.0. Anyone is free to open a pull request though. |
Not only this^^ but sometimes restarting Godot doesn't work if you've gone in deeper than a couple files. And, occasionally, a restart is not needed if I do dummy edits on the files in cyclic lock, in just the right order. What I am currently having to do while refactoring and breaking several files at once is temporarily downgrade the var and parameter typing to just So, regardless of whatever parts of this are being fixed in 4.0, it would be nice to at least be able to force a re-analysis of all dependencies in 3.x (or do it more often behind the scenes) so that we don't have to restart or resort to other trickery all the time just to get the parts that do work.... working again. |
The thing that I just started doing to try and get around this is whenever I have a class that frequently refers to other custom classes and those classes refer to it, is to have a dummy class that the custom class inherits from. Then whenever I need to refer to it for static typing or whatever, I do it against the dummy class instead. It makes it a bit strange in the editor and you have to make sure not to actually use the dummy class to do anything or have multiple classes inherit from it, but it does seem to prevent the cyclic errors for the most part (although I do sometimes get it with autoload scripts, but those are easier to fix). There are obviously downsides, like not having full autocompletion and the code being less readable, but it's better than constantly grappling with the classes and trying not to trigger the cyclic error. |
@HorseLuvver that is called an abstract class/interface, and it should work with autocomplete if you create dummy (virtual) empty methods just to declare its fields. These are basic concepts of Object Oriented Programming and are a feature of classes in general programming. However, this does not cover all cases of circular reference. It does help to some extent and I have been doing so for some time now. It is good, albeit tedius, practice. |
👍 |
In 3.5.1, it seems sometimes
That seems like a bug, but also a potential workaround (for some use cases) until 4.0? |
Bugsquad edit: This issue has been confirmed several times already. No need to confirm it further.
Windows 10 64-bit - Godot 3.1 alpha
Edit - Refined issue to focus on cyclic errors.
Certain uses of
class_name
can produce cyclic errors in situations where there are no cyclic references, and in fact sometimes no other references outside of the single one given.I've noticed this most frequently in tool script when using
is
to make a class comparison, but it seems to happen at times in normal script situations.Recreating it in a sample project has eluded me.
The text was updated successfully, but these errors were encountered: