How to handle preservations of linked IDs when they are effectively unused. #106321

Closed
opened 2023-03-30 17:55:27 +02:00 by Bastien Montagne · 10 comments

133dde41bb refactored how linked data 'directly linked' versus 'indirectly linked' status is handled in code, such that only linked IDs effectively used in current blend file are tagged as 'directly linked'.

This broke some existing use-case, where previous broken behavior was 'abused' to keep linked IDs in current .blend files even if they did not have actual real local usages. E.g. Texts data-blocks, or node groups... See #103867, #105687, #105786, and 'fixes' commits a60f651502 and 3d49d738b7.

A better solution than these temp hacks is needed. Here are three different proposals.

1. Keep track of IDs explicitly linked by users.

The idea here is to add a new flag to IDs, which would only be set for linked IDs that were actually selected by the user (as opposed to these implicitly linked as their dependencies).

These explicitly linked IDs would then always be kept in current blend file, unless users explicitly delete them (through regular ID deletion or Purge operation e.g.).

The 'Fake User' flag would then be fully ignored on linked data.

This solution would also help in case 'fake user' gets removed in the future? See #61209.

2. Make 'Fake User' Editable on Linked Data.

'Fake User' would be editable on linked data. Linked IDs with this flag set would always be considered as directly linked.

When linking a new ID, the value of the 'Fake User' flag in the library file would be ignored. Instead, the Fake User flag would be set or cleared based on the ID type (in a similar way as some ID types currently get a fake user by default on creation, e.g. texts)
This would imply adding a new IDType flag to identify such ID types, which would be a good side-cleanup thing.

3. Fully ignore 'Fake User' status of linked data.

This option would systematically clear that flag when reading linked data, and only keep linked data that is effectively used in the current .blend file.

User would then have to explicitly reference linked data they want to keep around, e.g. via custom property pointers.


This task is closely related to #99262.

133dde41bb refactored how linked data 'directly linked' versus 'indirectly linked' status is handled in code, such that only linked IDs effectively used in current blend file are tagged as 'directly linked'. This broke some existing use-case, where previous broken behavior was 'abused' to keep linked IDs in current .blend files even if they did not have actual real local usages. E.g. Texts data-blocks, or node groups... See #103867, #105687, #105786, and 'fixes' commits a60f651502 and 3d49d738b7. A better solution than these temp hacks is needed. Here are three different proposals. ### 1. Keep track of IDs explicitly linked by users. The idea here is to add a new flag to IDs, which would only be set for linked IDs that were actually selected by the user (as opposed to these implicitly linked as their dependencies). These explicitly linked IDs would then always be kept in current blend file, unless users explicitly delete them (through regular ID deletion or Purge operation e.g.). The 'Fake User' flag would then be fully ignored on linked data. This solution would also help in case 'fake user' gets removed in the future? See #61209. ### 2. Make 'Fake User' Editable on Linked Data. 'Fake User' would be editable on linked data. Linked IDs with this flag set would always be considered as directly linked. When linking a new ID, the value of the 'Fake User' flag in the library file would be ignored. Instead, the Fake User flag would be set or cleared based on the ID type (in a similar way as some ID types currently get a fake user by default on creation, e.g. texts) *This would imply adding a new IDType flag to identify such ID types, which would be a good side-cleanup thing.* ### 3. Fully ignore 'Fake User' status of linked data. This option would systematically clear that flag when reading linked data, and only keep linked data that is effectively used in the current .blend file. User would then have to explicitly reference linked data they want to keep around, e.g. via custom property pointers. ------------------ This task is closely related to #99262.
Bastien Montagne added the
Type
Design
Module
Core
Status
Confirmed
labels 2023-03-30 17:56:00 +02:00
Bastien Montagne added this to the 3.6 LTS milestone 2023-03-30 17:56:12 +02:00

Subscribed

*Subscribed*
Author
Owner

@brecht @dfelinto you guys have any opinions regarding proposed solutions, or other ideas? Think it would be good to properly address that issue for 3.6 LTS.

@brecht @dfelinto you guys have any opinions regarding proposed solutions, or other ideas? Think it would be good to properly address that issue for 3.6 LTS.
Author
Owner

@SimonThommes @eyecandy @Mets You guys may also have some ideas here?

@SimonThommes @eyecandy @Mets You guys may also have some ideas here?

I think we should have a discussion to figure out where we want to go with fake users and reference counting in general, and what we can change in 4.0, before committing to a solution here. Since it might change the conclusion.

(1) and (2) in a way are not that different. If "explicitly linked" is user editable it's like a local "fake user"? And the "fake user" from the original .blend is not relevant when linked, so in the UI that can be replaced with this.

For both #103867 and #105687 I think the proper solution is not to rely on this though. If a rig needs a script, we should have some way of attaching that script to the rig instead so it comes along and gets removed automatically as needed. For an add-on using a node group, it should also be linked through a custom property I think.

I think we should have a discussion to figure out where we want to go with fake users and reference counting in general, and what we can change in 4.0, before committing to a solution here. Since it might change the conclusion. (1) and (2) in a way are not that different. If "explicitly linked" is user editable it's like a local "fake user"? And the "fake user" from the original .blend is not relevant when linked, so in the UI that can be replaced with this. For both #103867 and #105687 I think the proper solution is not to rely on this though. If a rig needs a script, we should have some way of attaching that script to the rig instead so it comes along and gets removed automatically as needed. For an add-on using a node group, it should also be linked through a custom property I think.
Member

Quick 2 cents:

  • use_fake_user should only be considered on local IDs. The flag of linked IDs should be ignored, otherwise linked IDs end up filling up shot files, and can only be properly cleaned up with Python scripting.
  • If user wants to keep a linked ID even when it has no users, either simply don't allow it (sorry) or take the ugly design path and add a separate flag for that specific behaviour (use_fake_user_linked).

Of course a longer term solution would probably involve a rework of Blender's garbage collection or so, but that's probably a bigger project.

Quick 2 cents: - use_fake_user should only be considered on local IDs. The flag of linked IDs should be ignored, otherwise linked IDs end up filling up shot files, and can only be properly cleaned up with [Python scripting](https://projects.blender.org/studio/blender-studio-pipeline/pulls/105). - If user wants to keep a linked ID even when it has no users, either simply don't allow it (sorry) or take the ugly design path and add a separate flag for that specific behaviour (use_fake_user_linked). Of course a longer term solution would probably involve a rework of Blender's garbage collection or so, but that's probably a bigger project.
Bastien Montagne modified the milestone from 3.6 LTS to 4.0 2023-07-18 11:16:15 +02:00

I think (3) makes sense, but there is a problem that I think we need to solve along with it.

As far as I know, there is no way to attach a (auto-run) Text datablock to a rig without using Python scripting. In the Custom Properties panel you can not create datablock pointer properties. You can do it by defining a PointerProperty in Python, but of course to do that you need to be able to run a script first.

Can we make this possible, so that we can recommend that as the solution to keep around arbitrary datablocks from other datablocks going forward?

I think (3) makes sense, but there is a problem that I think we need to solve along with it. As far as I know, there is no way to attach a (auto-run) Text datablock to a rig without using Python scripting. In the Custom Properties panel you can not create datablock pointer properties. You can do it by defining a `PointerProperty` in Python, but of course to do that you need to be able to run a script first. Can we make this possible, so that we can recommend that as the solution to keep around arbitrary datablocks from other datablocks going forward?
Member

You can do it by defining a PointerProperty in Python, but of course to do that you need to be able to run a script first.

Slight correction: You don't need to define a PointerProperty, IDProperties support pointers, so you can just do this:
my_rig.data['script'] = bpy.data.texts['rig_script.py']
But it is correct that there is no UI way to do this. (Add-ons can provide a UI to do it, like Rigify does, and to do that, you indeed need a PointerProperty(type=Text))

I agree that implementing UI into bpy.ops.wm.properties_edit that allows the aforementioned line of code should be possible, and it is a nice way to address the use case where users would want linked data to stick around.

Only problem is that Operators can't get IDs passed to them, but if you pass ID type, name, and libpath, you're good to go.

I recently implemented this in an add-on, may it inspire: ID Management Pie
image

> You can do it by defining a `PointerProperty` in Python, but of course to do that you need to be able to run a script first. Slight correction: You don't need to define a PointerProperty, IDProperties support pointers, so you can just do this: `my_rig.data['script'] = bpy.data.texts['rig_script.py']` But it is correct that there is no UI way to do this. (_Add-ons can provide a UI to do it, like Rigify does, and to do that, you indeed need a `PointerProperty(type=Text)`_) I agree that implementing UI into `bpy.ops.wm.properties_edit` that allows the aforementioned line of code should be possible, and it is a nice way to address the use case where users would want linked data to stick around. Only problem is that Operators can't get IDs passed to them, but if you pass ID type, name, and libpath, you're good to go. I recently implemented this in an add-on, may it inspire: [ID Management Pie](https://projects.blender.org/studio/blender-studio-pipeline/pulls/127#issuecomment-982252) ![image](/attachments/d8a5ed93-0fbf-45c4-8b62-2e112b23541c)
Author
Owner

Adding proper UI support for custom properties to ID pointers seems doable, here is a quickly slapped prototype: !110458.

Adding proper UI support for custom properties to ID pointers seems doable, here is a quickly slapped prototype: !110458.
Author
Owner

And !111042 implements solution #3 above (always fully ignoring 'fake user' status of linked data - fairly trivial in fact).

And !111042 implements solution #3 above (always fully ignoring 'fake user' status of linked data - fairly trivial in fact).
Author
Owner

Committed as b3c7f3c8a9 and f052b18a65.

Committed as b3c7f3c8a9 and f052b18a65.
Blender Bot added
Status
Archived
and removed
Status
Confirmed
labels 2023-08-21 15:36:33 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#106321
No description provided.