How to take back the ownership of a component from the world? #13116
-
Is it possible to take back the ownership of component from world? Or replace it with another without Drop-ing. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
You can use
Please be careful with that since not dropping some value probably means leaking memory, which in the long run is going to make your program run out of memory and crash. |
Beta Was this translation helpful? Give feedback.
-
You should also be able to use the various remove component APIs on the world: those will return ownership of the returned values. |
Beta Was this translation helpful? Give feedback.
You can use
world.entity_mut(your_entity_id)
to get aEntityWorldMut
and then call.take::<YourComponentType>()
on it to get ownership of the component.Please be careful with that since not dropping some value probably means leaking memory, which in the long run is going to make your program run out of memory and crash.