Skip to content
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

"Cannot get class" the first time without running the editor #430

Closed
bbasics opened this issue Sep 27, 2023 · 10 comments
Closed

"Cannot get class" the first time without running the editor #430

bbasics opened this issue Sep 27, 2023 · 10 comments
Labels
question Not a problem with the library, but a question regarding usage.

Comments

@bbasics
Copy link

bbasics commented Sep 27, 2023

I have a godot project using godot-rust in a branch that I switch in and out frequently. Every time I checkout to the branch, I have to compile the rust project and then open the editor first (godot -e). If I run the project with godot before I get:

ERROR: Cannot get class 'MyClass'.
   at: instantiate (core/object/class_db.cpp:339)
WARNING: Node MyNode of type Motor cannot be created. A placeholder will be created instead.
     at: instantiate (scene/resources/packed_scene.cpp:205)

MyClass being the class defined in rust.

I think it should be possible to avoid opening the editor to run the project.

Is it a bug?

Thank you all !

@Bromeon
Copy link
Member

Bromeon commented Sep 27, 2023

Do you version this file?
https://godot-rust.github.io/book/gdext/intro/hello-world.html#extension_listcfg

@bbasics
Copy link
Author

bbasics commented Sep 27, 2023

Yes I do. However I switch between a branch where there are neither godot project nor the godot-rust project and another branch where both are there. So all the .godot files are removed.

However I would suspect the game to work without launching the editor if I coded the scene manually.

I am not sure it is related to godot-rust or gdextension though..

@Bromeon
Copy link
Member

Bromeon commented Sep 28, 2023

Yes I do. However I switch between a branch where there are neither godot project nor the godot-rust project and another branch where both are there. So all the .godot files are removed.

That is, you don't version it. With "version" I meant "commit to version control", meaning it would be restored upon switching to that branch again.

However I would suspect the game to work without launching the editor if I coded the scene manually.

Yes, but Godot requires the extension_list.cfg file if you want that. So make sure it's available.


There are possibly some sanity checks or auto-generation we could do (see #420), but in general, these things are dictated by Godot, not by gdext.

@Bromeon Bromeon added the question Not a problem with the library, but a question regarding usage. label Sep 28, 2023
@bbasics
Copy link
Author

bbasics commented Sep 28, 2023

It is versionned as I said. When I switch to the branch with the godot rust project, this file does come back, and is here whenever I try to run the game.

The only thing that is removed totally is the .godot folder. On the rust library, it is compiled like it would be the first time.

If this is a godot issue, which it probably is, I will move this issue to their repo.

Thanks for the help!

@Bromeon
Copy link
Member

Bromeon commented Sep 28, 2023

The only thing that is removed totally is the .godot folder. On the rust library, it is compiled like it would be the first time.

As I wrote: you need to make sure that this file is present whenever you launch Godot. How you achieve that with your branches is up to you.


If this is a godot issue, which it probably is, I will move this issue to their repo.

I think this is by design, even if I don't really like it.

But you can gladly bring up the discussion, it might be possible to remove this requirement. Probably the file is needed to track which extensions are being loaded; but an absent file could be understood as "all extensions in the project folder".

I'll close this issue then 🙂

@Bromeon Bromeon closed this as completed Sep 28, 2023
@bluenote10
Copy link
Contributor

bluenote10 commented Oct 1, 2023

Do you version this file? https://godot-rust.github.io/book/gdext/intro/hello-world.html#extension_listcfg

I made an interesting observation regarding this: I thought this is a great idea, because I'm currently switching between Godot 3 and Godot 4 branches, always deleting the .godot or .import folders, which means that I have to run the editor once to make the project work again.

However, my code contains init functions that do a load on resources like textures. After committing the extension_list.cfg I noticed that I still had to start the editor, because the resources had to be imported anyway (runtime errors with godot4 .). But now starting the editor was actually no longer possible at all! Apparently the order in which the editor is initializing everything is "load gdextensions before importing resources". This means that these init functions were now panicking trying to load the textures, and because of the crash, the editor wouldn't get to the point to actually import them. My first idea was to resolve this chicken-and-egg problem by "quickly" changing my init functions to avoid loading the resources. It turned out that this would have meant a bigger refactoring because making the usages of these resources optional wasn't straightforward (neither to "delete" the entire class). This reminded me of the issue #194 (comment) that it is currently not possible to mark a class as abstract, i.e., tell the editor to please not try to call init, which would be great to resolve such issues.

Fortunately it turned out that deleting the extension_list.cfg again can resolve the chicken-and-egg situation -- most likely because with a missing extension_list.cfg the resource importing happens first.

Another approach would be to actually version the imported resource files as well.

TL;DR surprisingly, versioning only the extension_list.cfg can actually result in making the project unusable after a checkout!

@bbasics
Copy link
Author

bbasics commented Oct 3, 2023

For my issue I actually confused the extension_list.cfg file with another. Keeping this file resolved my issue, but I wanted to avoid version anything in .godot so I just built a script to write it if it does not exist which is fine for my special case but may not be for others

@Bromeon
Copy link
Member

Bromeon commented Oct 3, 2023

@bluenote10 godotengine/godot#82554 might be potentially interesting here. Addressing the "code shouldn't run by default in the editor" at the core -- as opposed to our current #[class(tool)] workaround -- would also mean init() wouldn't be called from the editor anymore.

Of course, the problem may still exist for editor classes that need resources... Maybe it's worth filing an issue in Godot for that?

@Bromeon
Copy link
Member

Bromeon commented Oct 3, 2023

@bbasics

Keeping this file resolved my issue, but I wanted to avoid version anything in .godot so I just built a script to write it if it does not exist which is fine for my special case but may not be for others

This will break as soon as Godot changes the format. Since this file is mostly internal, that's not unlikely.

I'd rather ignore the entire folder and un-ignore this specific file; .gitignore allows exceptions.

@bbasics
Copy link
Author

bbasics commented Oct 3, 2023

I don't really agree, versionning this file is probably worse if godot is updated since it can lead to conflicts with the editor. I prefer to let the all .godot folder up to godot.
My script won't write anything if the file already exist so it should be ignored if godot update something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Not a problem with the library, but a question regarding usage.
Projects
None yet
Development

No branches or pull requests

3 participants