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

Add tool to update all scenes and resources to use UIDs for 4.4 #11639

Open
Meorge opened this issue Jan 26, 2025 · 3 comments · May be fixed by godotengine/godot#102071
Open

Add tool to update all scenes and resources to use UIDs for 4.4 #11639

Meorge opened this issue Jan 26, 2025 · 3 comments · May be fixed by godotengine/godot#102071

Comments

@Meorge
Copy link

Meorge commented Jan 26, 2025

Describe the project you are working on

Projects started in 4.3 that I want to migrate to 4.4

Describe the problem or limitation you are having in your project

According to the blog post "UID changes coming to Godot 4.4":

After upgrading the project to 4.4, you should re-save all scenes and resources to add any missing UID references. The editor will add them automatically as you save scenes/resources for the first time with 4.4, but it’s better to do it all at once to avoid random diffs appearing in version control later on.

This is much easier said than done, especially for projects that may have a lot of scenes and resources in them (and Godot does tend to encourage building lots of scenes).

Describe the feature / enhancement and how it helps to overcome the problem or limitation

A tool could be built in to the editor that simply opens each resource/scene, runs the "save" operation on it, then closes it and moves to the next resource/scene. For each item, this would be equivalent to the user double-clicking the resource/scene, pressing "Save", and closing it. However, by having the engine do it, it would be much faster than having the user go through each resource/scene file in their project and perform the steps manually, and would also eliminate the possibility of the user missing some files by mistake.

I brought this idea up in the RocketChat and it sounds like an existing mesh upgrade tool ("Upgrade Mesh Surfaces..."?) could be adapted for this, without too much extra work.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

This tool could run automatically when upgrading a project from 4.3 to 4.4.

Additionally, it could be found under Project > Tools in the menu bar.

If this enhancement will not be used often, can it be worked around with a few lines of script?

I imagine an editor script could be written to do this, but it would require users upgrading their project's Godot version to seek out, download, and run the script, rather than just having the editor do it automatically. Given the amount of friction that UIDs have already faced for 4.4, I think we should be trying to make the upgrade as seamless as possible, not (practically) requiring any external tools if possible.

Is there a reason why this should be core and not an add-on in the asset library?

See above

@KoBeWi
Copy link
Member

KoBeWi commented Jan 26, 2025

This can be achieved with a simple EditorScript.
I even had one I once ran in my project, but I seem to have lost it 🙃

@Meorge
Copy link
Author

Meorge commented Jan 26, 2025

That's good to hear! I also looked through the SurfaceUpgradeTool code last night and it looks pretty straightforward, be it in C++ or GDScript.

I still think it'd be very good to have as a built-in feature of Godot, such that users don't have to go find the editor script elsewhere on the web, or try writing it themselves and risk doing so improperly.

@Meorge Meorge linked a pull request Jan 27, 2025 that will close this issue
2 tasks
@KoBeWi
Copy link
Member

KoBeWi commented Jan 27, 2025

Some script I quickly pieced together (not fully tested):

@tool
extends EditorScript

func _run() -> void:
	upgrade_dir("res://")

func upgrade_dir(path: String):
	if FileAccess.file_exists(path.path_join(".gdignore")):
		return
	
	var to_reimport: PackedStringArray
	for file in DirAccess.get_files_at(path):
		var file_path := path.path_join(file)
		var ext := file.get_extension()
		
		if ext.get_extension() == "tscn" or ext.get_extension() == "scn" or ext.get_extension() == "tres" or ext.get_extension() == "res":
			var res := load(file_path)
			ResourceSaver.save(res)
		elif FileAccess.file_exists(file_path + ".import"):
			to_reimport.append(file_path)
		
	if not to_reimport.is_empty():
		EditorInterface.get_resource_filesystem().reimport_files(to_reimport)
	
	for dir in DirAccess.get_directories_at(path):
		if not dir.begins_with("."):
			upgrade_dir(path.path_join(dir))

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

Successfully merging a pull request may close this issue.

3 participants