makspll/bevy_mod_scripting

How do I correctly despawn Entities with scripts?

Closed this issue · 5 comments

zwazel commented

I despawn an entity (recursively) that has a script attached to it. but the script still "exists" and receives the events.

I'm currently only working with the Rhai implementation, so idk if this is a general problem or not. but its definitely not what i expect it to work like XD

zwazel commented

I have updated my Example in my Fork to showcase the issue:

https://github.com/zwazel/bevy_mod_scripting/blob/e383c5b97653a037a54451aa9ceea1cd31ff7c53/examples/rhai/multiple_events_rhai.rs#L108-L117

The example now immediately despawns the entity after calling "on_update" once.
The "on_test" is still being called by the scripts, even though their entity doesn't exist anymore.

(The script)

zwazel commented

I was experimenting a little bit, and interestingly in my example, out of the 10 entities, the context is only being removed from 9. so the "on_test" is called on only 1 of them.

Updated the example again that shows this.

zwazel commented

okay, there seems to be a problem in my own logic.
the crate does it as expected, now i just need to find my issue.
the example will be shortly updated, it works as intended

zwazel commented

Okay, nope.
there is indeed a bug.

(sorry for all the messages...)

Haha, you're right there is a bug, and it's really weird I haven't seen this before, guess I haven't had a situation where entity id != script Id and then I removed it? very good catch thanks!