Don't know if this has already been said but anyway,
This situation,
you have a parent entity with many children,
you are checking collisions for each child,
when any child collides you hide the parent,
although hiding and showing an entity will work
as a ResetEntity(), all the children still keep the
collision information when they are hidden and shown.
So when you show the parent again and check
collisions for each child, it will give an "Entity does not exist" if
the entities which collided with the children are deleted.
Two ways to correct this,
- Hiding or showing a parent will automatically reset the collision
information for all its children.
- Adding a new parameter to the ResetEntity() command
to also reset the collision for all the children if you want to (ResetEntity parent,True)
Run this code to look at it:
This situation,
you have a parent entity with many children,
you are checking collisions for each child,
when any child collides you hide the parent,
although hiding and showing an entity will work
as a ResetEntity(), all the children still keep the
collision information when they are hidden and shown.
So when you show the parent again and check
collisions for each child, it will give an "Entity does not exist" if
the entities which collided with the children are deleted.
Two ways to correct this,
- Hiding or showing a parent will automatically reset the collision
information for all its children.
- Adding a new parameter to the ResetEntity() command
to also reset the collision for all the children if you want to (ResetEntity parent,True)
Run this code to look at it:
Graphics3D 640,480,16,2 Const col1=1 Const col2=2 Collisions col2,col1,2,1 cam=CreateCamera() CameraRange cam,.01,200 PositionEntity cam,0,6,-6 TurnEntity cam,45,0,0 c=CreateCube() PositionEntity c,0,0,4 c2=CreateCube() EntityParent c2,c,True EntityType c2,col1 EntityColor c2,0,0,255 sph=CreateSphere() PositionEntity sph,-3,0,0 EntityColor sph,255,0,0 NameEntity sph,"RED sphere" EntityType sph,col2 While Not KeyDown(1) If CountCollisions(c2) HideEntity c2 EndIf If sph If MouseDown(1) MoveEntity sph,.01,0,0 If CountCollisions(sph) hiden=1 EndIf EndIf EndIf If KeyHit(57) FreeEntity sph EndIf UpdateWorld RenderWorld Color 255,255,255 Text 10,300,"Hold down LMB to move the sphere until it collides" Color 0,255,0 Text 10,330,"CountCollisions() of cube: "+CountCollisions(c2) If CountCollisions(c2) name$=EntityName(CollisionEntity(c2,1)) EndIf Text 98,350,"Colliding with: "+name If hiden=1 Color 255,255,0 Text 10,380,"Although the child (blue cube) is hiden now, it still return a collision." Text 10,400,"Hit SPACE to delete the sphere and get the 'bug'" EndIf Flip Wend MoveMouse 400,300:End