Switching hosting companies can affect your search engine ranking in several ways.
First is the location of the new server to which you will move your website. Some search engines like Google check the IP that the website uses, as one of their ranking rules is proximity to the user. If the new server is located in the same country as the previous one, then your search engine ranking should not be affected.
The loading speed of the website on the new location is also a factor. If the website is loading slower than 2 seconds on the new server, then Google will drop the website’s ranking. This means that the new server should be well-optimized to handle the hits towards your website faster.
Uptime is also a factor that should be considered during the transfer. If the website is down during the process, then this could decrease its search ranking. This is why it is recommended to leave the website on the origin server working until the transfer is completed, and you point the domain name to the new server. Then you should allow 72 hours for the DNS propagation to complete, make sure that search engine crawlers are properly crawling the website on the new server and only then stop the website on the old one.