Skip to content

fix: preserve entity references during template revert all#1756

Open
willeastcott wants to merge 1 commit intomainfrom
fix/template-revert-entity-references
Open

fix: preserve entity references during template revert all#1756
willeastcott wants to merge 1 commit intomainfrom
fix/template-revert-entity-references

Conversation

@willeastcott
Copy link
Contributor

@willeastcott willeastcott commented Feb 14, 2026

Summary

  • Fixes pressing Revert All on a template instance incorrectly clearing entity attribute references (e.g. script attributes of type entity) that point to entities within the template hierarchy
  • Adds a preserveEntityReferences option to Entity.delete() / Entities.delete() / deleteEntities() that skips reference nullification during deletion
  • Uses this option in the templates:revertAll redo and undo paths, where entities are immediately re-created with the same resource_id values

Root Cause

When Revert All deletes the template instance, deleteEntities() finds all entity references in the scene and sets any pointing to the deleted entities to null. The entities are then re-created with the same IDs via instantiateTemplate(), but by that point the references have already been permanently lost.

Fix

Skip reference nullification when the caller knows the entities will be immediately re-created with identical resource_id values, which is always the case during template revert.

Fixes #691

Test plan

  • Create a template and place it in the hierarchy
  • Create a script with an entity attribute and assign it to another entity
  • Assign the templated entity to that entity attribute
  • Modify something inside the template instance
  • Press Revert All
  • Verify the entity attribute still references the templated entity
  • Undo the revert and verify the reference is still intact

When Revert All is pressed on a template instance, the entity is deleted and re-created with the same resource_id values. The delete operation was nullifying all entity attribute references pointing to the deleted entities before they were re-created, causing those references to be permanently lost.

Add a preserveEntityReferences option to the entity delete API that skips reference nullification. Use it in the revert all redo/undo paths where entities are immediately re-created with identical IDs.

Fixed #691

Co-authored-by: Cursor <cursoragent@cursor.com>
@willeastcott willeastcott self-assigned this Feb 14, 2026
@willeastcott willeastcott added bug Something isn't working area: templates labels Feb 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: templates bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pressing revert all on template deletes it from attributes

1 participant