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

Editor re-starts (specifically executing _enter_tree() on tools) scenes when reimporting anything #92623

Closed
Bonkahe opened this issue Jun 1, 2024 · 3 comments

Comments

@Bonkahe
Copy link
Contributor

Bonkahe commented Jun 1, 2024

Tested versions

Reproducible in: 4.3 beta 1 (I don't know which commit sorry)

System information

Windows 10

Issue description

When updating to 4.3 beta 1, I noticed an issue with importing or re-importing any resource, this results in the scene your currently running within the editor to be reloaded, executing enter scene as if the scene has been loaded for the first time.
I currently have been working on a terrain system for 6 months, and it loads on the build, while generating the terrain it bakes to disc, this immediately resulted in an infinite loop of baking terrain, then reloading the scene and starting again.

I am unsure specifically if this is intended behavior or not, it is prohibitive to my project if it is and I would like to protest the decision to include this if so.

Thanks for any help.

Steps to reproduce

  1. Create new project
  2. Create a tool script with gd.print("Test") in the enter tree func
  3. Restart to let tool script be picked up by editor
  4. Run scene with the tool script present
  5. re-import the icon.svg default to godot projects

Minimal reproduction project (MRP)

reimporttesting.zip

@Rindbee
Copy link
Contributor

Rindbee commented Jun 1, 2024

Currently, exiting and re-entering the scene root tree is required:

  1. To process data related to scene history, we need to ensure that the scene is in the tree;
  2. Different scene roots may have the same name, so ensuring that only one scene is in the tree at the same time is necessary to ensure that the node path is correct.

If your code only needs to process when the tree is first entered, you can use a flag.

var first_enter_tree = true

func _enter_tree() -> void:
	if first_enter_tree:
		first_enter_tree = false
		# Put the code that needs to be processed for the first time here.

Or try putting it in _ready() if possible.

@Bonkahe
Copy link
Contributor Author

Bonkahe commented Jun 1, 2024

OK! soooo I got it sorted, and I'll leave a bit of an explanation for people in the future.

Basically my terrain system is generating page files for a virtual texture system when building. I had this tied to enter_tree, due to it being a good enough shorthand for whenever coming into an environment as well as having an erroneous belief that C# objects lose their non-serializable data on exit and enter tree (which is definitively not the case), however due to this update the scene fires the exit and enter tree function every time you re-import resources.
The solution is to entirely divorce from enter and exit tree, I did so for mine by having all regeneration entirely attached to a editor plugin calling a function whenever entering or exiting a scene, this can be done by fetching the terrain manager in a given scene, and when leaving scene (you can attach to the signal when adding your custom dock via the code: EditorInterface.get_selection().selection_changed.connect(yourdock.yourfunction) ) this lets you handle switching scenes properly versus exiting and entering the tree.
One note on this: Make sure that your also handling other scripts in the same manner, in my case I do a stamp based terrain and the stamps also used enter and exit tree, so I was getting lots of bad results which I thought were related to my page cache being invalidated, this was not the case just the stamps were acting up.

Hope this helps people!
Also, thank you @Rindbee very much, while it was a little headache, my terrain is now working with the new system, and is actually a whole lot more stable due to the refactor as I'm no longer needlessly rebuilding the terrain.

@Bonkahe
Copy link
Contributor Author

Bonkahe commented Jun 1, 2024

Closing due to worked around, and it's not a bug.

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

3 participants