var
  RayOrigin, RayDirection: TVector3;
  TileUnderMouseValid: Boolean;
  TileUnderMouse: TVector2Integer;
  RayHit: TRayCollision;
  RayHitInfo: TRayCollisionNode;
begin
  TileUnderMouseValid := false;
  MyNpcs.Exists := false;
  MyViewport.PositionToRay(Container.MousePosition, true, RayOrigin, RayDirection);
  RayHit := MyViewport.Items.WorldRay(RayOrigin, RayDirection);
  if RayHit <> nil then
  try
    if RayHit.Info(RayHitInfo) and
       (RayHitInfo.Item = Map) then
    begin
      TileUnderMouseValid := Map.Data.PositionToTile(
        RayHitInfo.Point.XY, TileUnderMouse);
    end;
  finally FreeAndNil(RayHit) end;
  MyNpcs.Exists := true; 
end;