-
|
I'm trying to destroy projectile and instantiate particle effect entities on the same collision callback. Both entities have "Script" components that have lambdas to handle construction and destruction of said scripts. The lambdas use script identifiers stored in the Script component to decide what to instantiate. The identifier for the particle effect seems to disappears when using the construction lambda after destroying the projectile entity. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
It's really hard to help without a repro. It can be anything, literally. I barely get what you're trying to do from the description. |
Beta Was this translation helpful? Give feedback.
-
|
Hi! Thanks for replying. I'm a big fan. Here's some snippets that hopefully clears things up. Here's the definition of my Script component that's a wrapper for a ScriptableEntity script This is in the script's OnCollisionEnterFunction().
Here's pseudo on how the scripting system flows My best guess is that the problem is to do with how I destroy and create entities. After destroying an entity I keep the ID to be reused for the next call to registry.Create(). This is because I've been using entt ids as indices into buffers for my rendering so I need them to be in a reasonable range (Idk if is a good idea) |
Beta Was this translation helpful? Give feedback.
I see. Well, this is risky at first glance and most likely your problem too:
InstantiateScript = [this]() {You're capturing
this, the address of the component assigned to the entity, is it?In this case, keep in mind that components are moved within a pool to optimize performance iterations. Unless you tell EnTT not to do that ofc, since everything is configurable here. 🙂
If you want stable pointers for your component type, add the following to your
Scriptclass:In this case,
thisis never invalidated until you destroy the component itself.Another option is to make the instantiation function static and pass the script to it as an a…