Add indicator to linked resources#109458
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
|
Please make sure your code is formatted properly locally before pushing again if you want checks to run, see here |
ea7d0bb to
f1ce477
Compare
This comment has been minimized.
This comment has been minimized.
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 |
Makes sense to take into account concerns raised in #102196:
|
|
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? |
|
I think the main (and most difficult) thing that should be done first it to detect amount of references to a resource.
(Please note that this is my personal opinion, and it may not coincide with the opinion of the Godot team members.) |
763256c to
d9c3e5b
Compare
|
Edge Cases aside, I'm done with this PR and it's ready for review! (I'm tired help) |
a61f0e0 to
44af052
Compare
|
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. 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 |
55cd5f1 to
a0e9cb4
Compare
|
Thanks! |



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:
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
HashMapto track how many times a Resource is referenced by a Node within a Scene.make_uniqueandmake_unique_recursiveis 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)
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_countcollects 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
Ais referenced by 3 Nodes, if you add a SubResourceB, 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_referencecollects 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_referenceand 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.
MoveEdit: NVM, moving functionality to icons hasnt been well supported by users in previous attempts by other PRsMake UniqueandMake Unique recursivefuncionality to Icons (Waiting on review for input)make_uniqueif there's only copy of the Resource or It's a subresourceHistory mismatch when undo-redoing packed scenes if they're open on the editor. (Waiting on review for input)Seems to have fixed itselfInconsistent Redoerror might happen??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