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

"Parser error: Could not resolve member" when a dictionary of preloads contains the scene trying to access said dictionary #90954

Closed
svioletg opened this issue Apr 20, 2024 · 5 comments · Fixed by #93346

Comments

@svioletg
Copy link

svioletg commented Apr 20, 2024

Tested versions

  • Reproducible in: v4.3.dev4.mono.official [df78c06], v4.3.dev5.mono.official [89f70e9]
  • Not occurring in v4.3.dev3.mono.official [36e943b], or v4.2.

System information

Godot v4.3.dev5.mono - Windows 10.0.19045 - Vulkan (Forward+) - dedicated Radeon RX 570 Series (Advanced Micro Devices, Inc.; 31.0.14057.5006) - AMD Ryzen 7 5700X 8-Core Processor (16 Threads)

Issue description

What's intended is to use a dictionary of preloaded scenes as a source to load up in-game menus from, like below:

var scenes: Dictionary = {
	'ExampleMenu': preload('res://example_menu.tscn'),
	'ExampleMenuTwo': preload('res://example_menu_2.tscn')
}

This is stored inside of the "MenuManager" scene's only script, and is made globally accessible by having a global.gd autoload declare the following:

extends Node

var menu_manager: MenuManager

...and then have the MenuManager scene assign itself in its _enter_tree() function:

func _enter_tree() -> void:
	Global.menu_manager = self
	print(self)
	print(Global.menu_manager)

As early as 4.3 snapshot 4, trying to access this dictionary from a scene that is itself preloaded in said dictionary, such as with the line var inst: Control = Global.menu_manager.scenes['ExampleMenuTwo'].instantiate(), this starts causing the Parser Error: Could not resolve member "scenes". error which prevents the game from running. If, in this case, ExampleMenu is removed from the definition of scenes, then everything works as normal.

Steps to reproduce

Create two scenes to test with, and in another scene / script, define a dictionary including both of them.

var scenes: Dictionary = {
	'ExampleMenu': preload('res://example_menu.tscn'),
	'ExampleMenuTwo': preload('res://example_menu_2.tscn')
}

Have a script within example_menu.tscn - attached to any node within the scene - that tries to access this dictionary.

func _on_button_pressed() -> void:
	assert(Global.menu_manager)
	assert(Global.menu_manager.scenes)
	var inst: Control = Global.menu_manager.scenes['ExampleMenuTwo'].instantiate()
	add_child(inst)

This will cause the parser error.

Minimal reproduction project (MRP)

4.3d5-dictionary-bug.zip

Production edit: added gdscript highlighting

@jonathansty
Copy link

I've got a similar issue, in my case I store some resources that contain data about each different team the player can be part of.

@matheusmdx
Copy link
Contributor

Bisecting points to #85501 as the culprit

image

@akien-mga akien-mga moved this from Unassessed to Release Blocker in 4.x Release Blockers May 7, 2024
@akien-mga
Copy link
Member

CC @Jordyfel @godotengine/gdscript

@akien-mga
Copy link
Member

See also #90362.

@github-project-automation github-project-automation bot moved this to For team assessment in GDScript Issue Triage May 17, 2024
@vnen vnen moved this from For team assessment to Up for grabs in GDScript Issue Triage May 18, 2024
@vnen vnen moved this from Up for grabs to In progress / Assigned in GDScript Issue Triage May 18, 2024
@adamscott
Copy link
Member

adamscott commented May 25, 2024

For the MRP, my PR (#92326) fix it, but you need to make sure that you can save the global class without error (by commenting the autoload reference first) to make sure it's registered as a global class. Then, you can put back the commented line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Release Blocker
Archived in project
5 participants