X Tutup
Skip to content

Add indicator to linked resources#109458

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
SatLess:DumbRes
Nov 4, 2025
Merged

Add indicator to linked resources#109458
Repiteo merged 1 commit intogodotengine:masterfrom
SatLess:DumbRes

Conversation

@SatLess
Copy link
Contributor

@SatLess SatLess commented Aug 9, 2025

Attempts to somewhat implement
godotengine/godot-proposals#904 , godotengine/godot-proposals#9603 , godotengine/godot-proposals#10319 (comment)

Feature

Adds an indicator to tells whether a resource is shared. The button's tooltip shows the number of times a Resource was shared, along with whether there are subresources to be made unique:

showtime

Left Click on the Icon makes Resources Unique. Right Click - Recursive

Implementation

For this feature, after a lot of trial and error, I settled for reduz's approach of using a
HashMap to track how many times a Resource is referenced by a Node within a Scene.

  • If a Resource is referenced more than once, you can make it unique (recursively or not).
  • If there's only one instance of a Resource, it's already unique, so make_unique and make_unique_recursive is disabled.

Note

Duplicating built-in SubResources is also disabled if the 'Parent' Resource wasn't previously made unique. This is because Making a SubResource unique does not matter if the parent isn't also duplicated. See #109458 (comment) (gradient example)

  • External Resources are not added to the HashMap — since we can't for certain indicate how many of them there are.
    Outside from that, I would separate this feature into two parts:

SceneTree Operations


In the Scene tree, you can add, delete, duplicate and paste nodes. Each time you do these operations, update_resource_count collects built-in non-empty Resources and add them to the HashMap, along with their respective Node. So basically you update the Resource counter each time you do these operations.


Inspector Operations

Each time you made a revelvant change to a property that holds a Resource (e.g Made a Resource unique, added a resource to an Array, etc), you update the Resource counter like above, inserting the Resource and its Node in the HashMap.

Note

When setting Subresources in the inspector (if not external), they should have the same number of References as the parent. So if Reference A is referenced by 3 Nodes, if you add a SubResource B, it should also be linked to 3 Nodes.

It uses a much "simpler" version of update_resource_count (although they could be merged but it would make using this API much more cumbersome for the Inspector and SceneTree). update_node_reference collects the Resources found withing a single property and either removes or adds to the HashMap. That way you're only dealing with a specific property is being set and not touching what's already added.

In short, The inspector part was the most tricky, as I did have to fix all the edge cases found when making unique, setting or removing Resources . As of 09/28, it's pretty clean all things considered. Using strictly update_node_reference and tweaking some pre existing code made it much cleaner than it previously was.

To-Do List

The following is a to-do list of everything that should be dealt with. There are some things left undetermined on how they should work, so I added Waiting for Input right after the task.

  • Display a warning indicator for sub resources as to why they can't be duplicated (Waiting on review for input)
  • Move Make Unique and Make Unique recursive funcionality to Icons (Waiting on review for input) Edit: NVM, moving functionality to icons hasnt been well supported by users in previous attempts by other PRs
  • Hashmaps clears and updates itself when Nodes are Added/Removed from a scene
  • Disable make_unique if there's only copy of the Resource or It's a subresource
  • Update Hashmap through other means, such as using Resource Picker
  • Counter not updating once you've done an operation.
  • Track Subresources
  • Bulk-Setting Node's Resources does not add them to hashmap.
  • Duplicated Arrays full of Resources do not increase counter for some reason.
  • External SubResources made unique should be included in the Hashmap, pointing to the parent's Nodes.
  • Find better way of knowing whether a resource is external or not
  • History mismatch when undo-redoing packed scenes if they're open on the editor. (Waiting on review for input) Seems to have fixed itself
  • Empty Resources/Sub resources using the wrong icon (fixes itself after saving)
  • Arrays (probly Dictionaries too) don't update counter when making unique
  • Inconsistent Redo error might happen??
  • Fix edge case when saving to disk/deleting resource from disk
  • Dictionaries with Resources as Keys don't show an icon
  • Edge Case with SubResources not showing the correct amount after adding them to a Resource already referenced by multiple nodes

Test Project

Added a test project so people interested in this feature can test it. It's a pretty dynamic feature though, so please toy around it and report any weird behavior!
indicator-test.zip

@fire fire changed the title Add Indicator to Resources That Are Linked Add indicator to linked resources Aug 9, 2025
@AThousandShips AThousandShips added this to the 4.x milestone Aug 11, 2025
@SatLess

This comment was marked as outdated.

@AThousandShips
Copy link
Member

Please make sure your code is formatted properly locally before pushing again if you want checks to run, see here

@SatLess SatLess force-pushed the DumbRes branch 2 times, most recently from ea7d0bb to f1ce477 Compare August 13, 2025 00:36
@SatLess

This comment has been minimized.

@dawdle-deer
Copy link
Contributor

So the counter idea would be scrapped, being replaced by an icon instead.

I do much prefer the counter - perhaps there's a middle ground that still offers one without the effort of tracking scene-external link counts. Maybe it could display the scene-local link count if it's internal, and then if it's external, make it instead read N or Ext or something?

@SatLess
Copy link
Contributor Author

SatLess commented Aug 15, 2025

Local duplicated Resources now have a counter
image

External Resources use an icon, and can be turned into local if clicked:
AAAAAAAAAA

Sadly, despite 5 days trying to get it to work, Subresources will not use the counter (unless a way is found ofc). It works pretty unreliably:
Why

Kinda upsetting, since that is mostly why I decided to make this PR. Will make the finishing touches needed , will try to indicate that making subresources unique is sorta pointless, and will leave it as is for review.

EDIT: Maybe I could in fact track the amount of sub resources locally, but it wouldn't do much more than that, unless you made their parent Resource unique

@arkology
Copy link
Contributor

Adds an icon on the side of a resource if it is not unique.

Move Make Unique and Make Unique recursive to Icons

Makes sense to take into account concerns raised in #102196:

User feedback has shown that this change isn't always a clear improvement, because:

The icon eats up horizontal space that's already limited here, cutting the text or previews significantly.
It breaks user expectations to no longer have load options next to Clear/Save/etc.

@SatLess
Copy link
Contributor Author

SatLess commented Aug 15, 2025

The icon for sub resources is more of a suggestion, one I'm particularly not that fond of. Maybe changing the theme of The Sub resource to indicate that? Or maybe adding a notification when trying to make that resource unique?

@arkology
Copy link
Contributor

I think the main (and most difficult) thing that should be done first it to detect amount of references to a resource.
On UI side:

(Please note that this is my personal opinion, and it may not coincide with the opinion of the Godot team members.)

@SatLess SatLess force-pushed the DumbRes branch 3 times, most recently from 763256c to d9c3e5b Compare August 16, 2025 01:50
@SatLess
Copy link
Contributor Author

SatLess commented Aug 16, 2025

Edge Cases aside, I'm done with this PR and it's ready for review! (I'm tired help)

@SatLess SatLess marked this pull request as ready for review August 16, 2025 01:59
@SatLess SatLess requested a review from a team August 16, 2025 01:59
@SatLess SatLess requested a review from a team as a code owner August 16, 2025 01:59
@SatLess SatLess force-pushed the DumbRes branch 3 times, most recently from a61f0e0 to 44af052 Compare August 22, 2025 23:36
@SatLess
Copy link
Contributor Author

SatLess commented Aug 22, 2025

Hey everyone, small update: Reinforced Support for Subresources, so they're taken into account when making external ones unique, and also when they're deleted with the parent. Arrays/Dictionaries are also using the counter now.
The PR is in a functional state, besides some quirks, so It's 'okay' for use (at least for my projects). This PR def needs some refactoring, perhaps some optimization ,reducing recursion calls, but I'll force myself to take a break from it until Godot 4.6 starts development, around the time someone from the Godot team might actually take a look at this.

Note (mostly to self): Subresources in this PR are treated as inseparable from their parents, as it's impossible for a Resource and its nested child not have the same Nodes referencing them. So I took advantage of this when needed to keep better track of Subresources' counter. Also, dont use Vscode for git, it suckssss

@SatLess SatLess force-pushed the DumbRes branch 3 times, most recently from 55cd5f1 to a0e9cb4 Compare August 23, 2025 00:15
@Repiteo Repiteo merged commit dc0aa56 into godotengine:master Nov 4, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Nov 4, 2025

Thanks!

@Repiteo Repiteo linked an issue Nov 4, 2025 that may be closed by this pull request
@SatLess SatLess deleted the DumbRes branch November 4, 2025 23:09
@SatLess SatLess restored the DumbRes branch November 4, 2025 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add indicator to resources that are unique

10 participants

X Tutup