How to attach a Spatial to two nodes at the same time

Can I attach a Spatial to two nodes at the same time? Now when i attach it to the second one it is removed from the first one
(Only one of the two node containers is attached to the rootNode of the SimpleApplication)

I’ve found no way to do this yet. But I’m very interested in.

For the moment, I simply duplicate it. (to fake a cyclic world)

No, you can’t do it. Neither can you attach your arm to two different bodies at the same time.

If you explain more about what you are really trying to do then we might be able to show you the proper way. For example, meshes can be shared across different geometries.

1 Like

The simple answer is no. Nodes only have a single parent and if you attach them to a new parent they remove from the old one.

Whether there is some “tricky” way to do this I’m not sure but I highly doubt it as any cached values etc would be invalid for one of the two instances.

I think it’s a dangerous thing to do, just attach the base model twice and you can always use a control to synchronize the two objects.

@pspeed said: No, you can't do it. Neither can you attach your arm to two different bodies at the same time.

If you explain more about what you are really trying to do then we might be able to show you the proper way. For example, meshes can be shared across different geometries.

Ok i need an arbitrary number of “lists” which implement the Collidable interface so that i can add one node to multiple of these lists and then ceck a collision with listA when actionX happens and with listB when actionY happens. I thought using the node class was a good idea because it does the collideWith checking. I could not find a special collision container for such things. I understand that normally it is not a good idea to allow adding a spatial to two nodes :wink:

Why not use collision groups?

@simon.heinen said:
@pspeed said: No, you can't do it. Neither can you attach your arm to two different bodies at the same time.

If you explain more about what you are really trying to do then we might be able to show you the proper way. For example, meshes can be shared across different geometries.

Ok i need an arbitrary number of “lists” which implement the Collidable interface so that i can add one node to multiple of these lists and then ceck a collision with listA when actionX happens and with listB when actionY happens. I thought using the node class was a good idea because it does the collideWith checking. I could not find a special collision container for such things. I understand that normally it is not a good idea to allow adding a spatial to two nodes :wink:

Not only that, it physically cannot be done.

So, if I get this straight, you wanted to use node to avoid having to do this?
[java]
for( Collidable c : myColliders ) {
c.collideWith( toHit, myResults );
}
[/java]

Seems a lot of baggage to take on to avoid a couple lines of code.

1 Like
So, if I get this straight, you wanted to use node to avoid having to do this? [java] for( Collidable c : myColliders ) { c.collideWith( toHit, myResults ); } [/java]

Seems a lot of baggage to take on to avoid a couple lines of code.

You were right, I now changed it and its much easier this way :slight_smile: I didn’t expect the nodes to take into account if they are part of a complex scene graph, so e.g. the translation and rotation of its parents but it works fine :slight_smile: Thanks for your help

@simon.heinen said:
So, if I get this straight, you wanted to use node to avoid having to do this? [java] for( Collidable c : myColliders ) { c.collideWith( toHit, myResults ); } [/java]

Seems a lot of baggage to take on to avoid a couple lines of code.

You were right, I now changed it and its much easier this way :slight_smile: I didn’t expect the nodes to take into account if they are part of a complex scene graph, so e.g. the translation and rotation of its parents but it works fine :slight_smile: Thanks for your help

In fact, this is why they can only be a child of one parent at a time. We’ve come full circle. :slight_smile: