amethyst / amethyst/specs

Allow components to perform cleanup (with access to the World) when they are removed

Ouverte
#723 5 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
feature-request
Langage dominant
Rust
Étoiles
2.6k
Forks
215
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

## Description
Allow components one last access to the world when they are deleted. This could be done by either:

1. Allowing some sort of call inside of `Drop` that gets the encompassing World (unlikely, probably really unsafe, stinks of globals)
2. Creating some sort of trait that acts like Drop but allows the component to access the world like a System does. Perhaps it could be named `Cleanup` or something?

## Motivation
I have a component that represents ownership over some physics objects. When the entity holding that component is deleted, I want the physics objects to also be deleted. The problem is that inside `Drop`, I have no access to the physics world because it's a resource. :(

## Drawbacks

* **Is it a breaking change?** No, features are only added
* **Can it impact performance, learnability, etc?** The performance of deleting large amounts of entities with components that require cleanup may be impacted. However, due to monomorphization, if you go with the cleanup trait then there will be no code generated for components without it, just like `Drop`. That means only code that explicitly opts into this feature will be impacted

## Unresolved questions
None right now

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.