Jump to content

[IG] How to prevent an entity child node from being destroyed on entity type change


photo

Recommended Posts

Hi,

At runtime, we are creating and then attaching some node to an entity inner child. For example, we have an entity with a dummy placed at some key points inside (think of it as a socket node), and we create a node (could be a camera, could be a mesh) and then attach it to the entity during run time. We keep a NodePtr to the added node and use it to move/rotate it.

All work great until we reload the database or we receive a CIGI packet that changes the entity type, and this of course deletes the socket dummy node in the entity node. And it apparently also deletes the node we attached to it, hence our stored NodePtr points to nothing and we crash.

  • Is there a way to "catch" the entity type chane event so we can handle this case more nicely
  • Is there any other way to attach a node to the entity with code at run-time. I though about using a child entity, but this can leads to other issues (the child id may be needed by the sim, we can't reserve it, and we need to dynamically change the content, its not a fixed set)

Thanks!

Link to comment

Hello! 

On 3/8/2023 at 9:01 PM, Amerio.Stephane said:

Is there a way to "catch" the entity type chane event so we can handle this case more nicely

no, there is no callback for changing the entity type.
we will add in 2.17 two new callbacks (they are already implemented)
- Entity::addOnBeforeChangeTypeCallback
- Entity::addOnChangedTypeCallback

On 3/8/2023 at 9:01 PM, Amerio.Stephane said:

Is there any other way to attach a node to the entity with code at run-time. I though about using a child entity, but this can leads to other issues (the child id may be needed by the sim, we can't reserve it, and we need to dynamically change the content, its not a fixed set)

You сan attach the node not to the model itself, but to the root node. 

some_part_node->getRootNode();
// or
entity->getNode();

this node is not deleted or changed when the type is changed.

 

Link to comment
4 hours ago, cash-metall said:

You сan attach the node not to the model itself, but to the root node. 

this node is not deleted or changed when the type is changed.

Ooh this is a nice thing to know! Thanks.

In the mean time, I found a way to be alerted when an object has been destroyed. I created a "ShutdownComponent" whose only role is to call a callback when it is itself destroyed (in its shutdown method). By adding this component to our additional node, at least we can be alerted when it has been destroyed and do some cleanup or recreate it.

Link to comment
×
×
  • Create New...