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

Godot 4.2 is unable to preload resources that DO exist. #85809

Open
Bloxxel64 opened this issue Dec 5, 2023 · 7 comments
Open

Godot 4.2 is unable to preload resources that DO exist. #85809

Bloxxel64 opened this issue Dec 5, 2023 · 7 comments

Comments

@Bloxxel64
Copy link

Bloxxel64 commented Dec 5, 2023

Tested versions

This issue did not occur before i upgraded to 4.2.

System information

Linux Mint on GD 4.2 stable

Issue description

When attempting to instantiate a scene through code, you first have to preload it, but for some reason godot is saying that it does not exist:

extends Node2D


# Called when the node enters the scene tree for the first time.
func _ready():
	var roomnum = randi() % 3
	
	var rooms = [preload("res://scenes/rooms/emptyrooms/Empty1.tscn"), preload("res://scenes/rooms/emptyrooms/Empty1.tscn"), preload("res://scenes/rooms/emptyrooms/Empty3.tscn")]
	
	var dospawn = rooms[roomnum].instantiate()
	add_child(dospawn)
	print(roomnum)

image

image

Steps to reproduce

Download the project, open it, and debug run it.

Minimal reproduction project (MRP)

project.zip

@rsubtil
Copy link
Contributor

rsubtil commented Dec 6, 2023

The error message is really cryptic and unhelpful. It seems the issue is due to a loading cycle. On base.tscn you load the inst.gd script with loads that same scene:

extends Node2D


# Called when the node enters the scene tree for the first time.
func _ready():
	var baller = preload("res://base.tscn")
	add_child(baller)

If you comment/remove that _ready function, the scene loads normally again.

This issue did not occur before i upgraded to 4.2.

Did you upgrade from any 4.x version, or earlier from 3.x?

@Bloxxel64
Copy link
Author

Bloxxel64 commented Dec 8, 2023

The error message is really cryptic and unhelpful. It seems the issue is due to a loading cycle. On base.tscn you load the inst.gd script with loads that same scene:

im sorry im not really sure what details i need to provide.

extends Node2D


# Called when the node enters the scene tree for the first time.
func _ready():
	var baller = preload("res://base.tscn")
	add_child(baller)

well im a dumbass, the code is incorrect.

If you comment/remove that _ready function, the scene loads normally again.

ill... try that...

@rsubtil
Copy link
Contributor

rsubtil commented Dec 8, 2023

im sorry im not really sure what details i need to provide.

I meant that the error Godot gives is not clear; it wasn't about your report 🙂

I don't know if your scenario is supposed to work or not, but since you mentioned that it has happened since you ported this code to 4.2, this might be a regression. What was the previous Godot version you were using?

@Bloxxel64
Copy link
Author

im sorry im not really sure what details i need to provide.

I meant that the error Godot gives is not clear; it wasn't about your report 🙂

I don't know if your scenario is supposed to work or not, but since you mentioned that it has happened since you ported this code to 4.2, this might be a regression. What was the previous Godot version you were using?

the project is only from 4.1, but i only got errors when i upgraded to 4.2, incidentally. sometimes godot will say the scenes are corrupted when i try to open them for some reason

@francescarpi
Copy link

Hi.

I've got the same issue on v4.2.stable.official [46dc277]

With the "preload" line, an error raises when Godot starting. Line 140 of "bug.tscn" references the "bug.gd" script.

image

If I comment the line, error message disappear.

@francescarpi
Copy link

Changing preload for load works well. Seen in this other reported issue

#85081 (comment)

@WhalesState
Copy link
Contributor

WhalesState commented Jun 7, 2024

Using the MRP, I have found that you are preloading base.tscn inside base.tscn and adding it as a child without instantiating it.

from the variable name i think you just wants to add the other scene ball.tscn to the base.tscn as a child, so this code should work fine without raising any issues.

Update the inst.gd script and reload the project from Project menu.

func _ready():
	var baller = preload("res://ball.tscn").instantiate()
	add_child(baller)

If I'm wrong and you want to preload the same scene inside itself, then you can try other methods like self.duplicate() for example, since the packed scene is already loaded.

Edit: Using var baller = self.duplicate() and adding it as child will raise this error inst.gd:7 @ _ready(): Can't add child 'Node2D' to itself.

I'm thinking if this should be considered as an issue, peloading Scene(A) which is using Script(A) inside Script(A) and adding it as a child to Scene(A), it will be an infinity loop. Maybe the compiler should raise an error when preloading a scene which is using the same script or preloading the same script inside itself, to prevent crashing the editor when using tool scripts.

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

No branches or pull requests

5 participants