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 load because it doesn't expose any class to Godot error when changing scene to the second time #402

Open
steven-thegamer opened this issue Jun 29, 2024 · 3 comments

Comments

@steven-thegamer
Copy link

I got these error when I try to load a scene for the second time.

Pythonscript 0.50.0 (CPython 3.8.5.final.0)
hi
Cannot load res://test_node.py (test_node) because it doesn't expose any class to Godot

The 'hi' is from a python script attached to a Godot Node with the task to print('hi') on ready. When I change the scene to another scene and open the same scene again, this error pops up as if it can't load the python script. Not the node, but the script itself only. This is what the script does.

from godot import exposed, export
from godot import *


@exposed
class test_node(Node):
	def _ready(self):
		print('hi')

What's wrong with this and does anoyne have a slution?

@hqmdokkai
Copy link

Plese reset godot to fix error

@S0u1y
Copy link

S0u1y commented Nov 29, 2024

Bumping this, because I hit a very similar problem. Reloading the project doesn't work, I tried resetting godot (turning it off and on) didn't help. Also this problem happens only if the scene contains a python script in a node.. I "fixed" it by changing the script to a GDScript, but that isn't really a good solution..

Have you or anyone else found a fix for this?

@S0u1y
Copy link

S0u1y commented Nov 30, 2024

Bumping this, because I hit a very similar problem. Reloading the project doesn't work, I tried resetting godot (turning it off and on) didn't help. Also this problem happens only if the scene contains a python script in a node.. I "fixed" it by changing the script to a GDScript, but that isn't really a good solution..

Have you or anyone else found a fix for this?

Okay, I have fixed it by loading all the scenes only once in an autoloaded singleton script and then swapping to them when I need to;

SceneSwapper.gd:

var scenes = {
	"AnalysisStage": load("res://AnalysisStage.tscn"),
	"Game": load("res://game.tscn"),
	
}

func _ready():
#     This loads all menu scenes from a project directory
	var directory = Directory.new()
	if directory.open("res://MainMenuScreens/") == OK:
		directory.list_dir_begin()
		var file_name = directory.get_next()
		while file_name != "":
			if file_name == "." or file_name == ".." or file_name.begins_with("__"):
				file_name = directory.get_next()
				continue
			if file_name.ends_with(".tscn"):
				scenes[file_name.split(".tscn")[0]] = load("res://MainMenuScreens/" + file_name)
			
			file_name = directory.get_next()
	

#potentially unsafe
func get_scene(scene_name) -> PackedScene:
	return scenes[scene_name]

Scene Swapping:

func _on_MainMenu_button_down():
	get_tree().change_scene_to(SceneSwapper.get_scene("Main Menu"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants